Can I install puppet modules through puppet manifest?

别来无恙 提交于 2019-12-04 16:29:45

问题


Primary goal is to add all puppet modules automatically, so that all dev-env's and prod-env could be started with one command. How can I install puppet modules through puppet manifest?


回答1:


We've been happily using librarian-puppet to sync all 3rd party modules, it supports setting the modules' locations and versions. So production and dev run the exact same code. The usage is one liner

librarian-puppet install

In other cases we have a shell script that runs puppet two times, one time a minimal module that is only responsible for fetching the required modules, and then the full blown puppet flow when all modules are available.




回答2:


The "Puppet module" type and provider does exactly that:

module { 'author/mymodule':
  ensure   => present,
}
module { 'puppetlabs/stdlib':
  ensure => '2.6.0',
}
module { 'puppetlabs/stdlib':
  ensure     => present,
  modulepath => '/etc/puppet/modules',
}

Recent versions of Puppet also have a puppet module command that allows you to install arbitrary Puppet modules from the Puppet forge, example:

$ puppet module install rcoleman/puppet_module
Notice: Preparing to install into /home/anarcat/.puppet/modules ...
Notice: Created target directory /home/anarcat/.puppet/modules
Notice: Downloading from https://forgeapi.puppetlabs.com ...
Notice: Installing -- do not interrupt ...
/home/anarcat/.puppet/modules
└── rcoleman-puppet_module (v0.0.3)

Other alternatives include:

  • librarian
  • r10k (cited as a replacement for librarian), supports dynamic environments and much more

r10k is now part of Puppet Entreprise 2015.03, so it can certainly be considered best practice.




回答3:


Here is an example of mine:

  $module_stdlib = 'puppetlabs-stdlib'
  exec { 'puppet_module_stdlib':
    command => "puppet module install ${module_stdlib}",
    unless  => "puppet module list | grep ${module_stdlib}",
    path    => ['/bin', '/opt/puppetlabs/bin']
  }

Where $module_stdlib is a module I whant to install. The /bin path is a path where the grep comes from. And the /opt/puppetlabs/bin is a path where for the puppet binary exists in my installation.




回答4:


Seems that writing module for installing puppet modules is possible - it'll be just wrapper for puppet module tool. However, I didn't hear about such module yet.

I suppose this mechanism of installation is not popular because often you need to modify installed module, do some customizations. Practical tool for management of such modifications is version control system. For example, in our team we keep /etc/puppetlabs/puppet directory in git repostitory. After installation of any module from Puppet Forge we add its files to version control and push it to remote git server. Our internally developed modules are also kept in this repository. This way, several puppet masters (dev and prod environments) are synchronized with this central repository and always have up-to-date versions of all modules.




回答5:


I did this and it seemed to work

exec { 'puppet-fstab':
    path => '/bin:/usr/bin',
    command => 'puppet module install -i /usr/share/puppet/modules/AlexCline-fstab >>/tmp/err.log',
}


来源:https://stackoverflow.com/questions/16774980/can-i-install-puppet-modules-through-puppet-manifest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!