Installing a puppet module from a manifest script

后端 未结 8 2181
不思量自难忘°
不思量自难忘° 2020-12-12 15:27

I\'m using puppet to provision a vagrant (ubuntu based) virtual machine. In my script I need to:

sudo apt-get build-dep python-lxml

I know

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-12 15:36

    Inspired by wtanaka.com's answer, I implemented a solution like below which I think is much more readable.

    1) create a new ruby file called 'puppet_deps.rb' under the same folder as Vagrantfile with code like below:

    def install_dep(name, version, install_dir = nil)
        install_dir ||= '/etc/puppet/modules'
        "mkdir -p #{install_dir} && (puppet module list | grep #{name}) || puppet module install -v #{version} #{name}"
    end
    

    2) In your Vagrantfile, you can load this ruby file and use it to specify the puppet dependency:

    # on top of your Vagrantfile
    require './puppet_deps'
    ...
    ...
    # in your vm definition, use a shell provisioning this:
    config.vm.provision :shell, :inline => install_dep('puppetlabs-firewall', '1.1.3')
    config.vm.provision :shell, :inline => install_dep('puppetlabs-stdlib', '4.3.2')
    

提交回复
热议问题