automate VM building using puppet

asked 2014-05-20 04:24:33 -0500

puppetlearners gravatar image

updated 2014-05-20 10:41:49 -0500

spuder gravatar image

Hi,

We are trying to automate Building VM using puppet with the help of vagrant. We have a host machine which is a Puppet agent on which VM is to be built. We created the following manifest to automate the process

file{'/home/VagrantVM':
ensure => directory,
owner => 'root',
group => 'root',
}

We are able to install VirtualBox and Vagrant successfully, so omitting that part. Then, from the Vagrant directory, we try to generate the vagrantfile using puppet with,

exec{'Init_Box':
cwd => '/home/VagrantVM/',
command => '/usr/bin/vagrant init',
}

The above manifest script returns the following error:

Notice: /Stage[main]/Vmclass/Exec[Add_Box]/returns: /opt/vagrant/embedded/gems/gems/vagrant-1.5.4/lib/vagrant/shared_helpers.rb:69:in `expand_path': couldn't find HOME environment -- expanding `~' (ArgumentError)
Notice: /Stage[main]/Vmclass/Exec[Add_Box]/returns:     from /opt/vagrant/embedded/gems/gems/vagrant-1.5.4/lib/vagrant/shared_helpers.rb:69:in `expand_path'
Notice: /Stage[main]/Vmclass/Exec[Add_Box]/returns:     from /opt/vagrant/embedded/gems/gems/vagrant-1.5.4/lib/vagrant/shared_helpers.rb:69:in `user_data_path'
Notice: /Stage[main]/Vmclass/Exec[Add_Box]/returns:     from /opt/vagrant/embedded/gems/gems/vagrant-1.5.4/lib/vagrant/plugin/manager.rb:16:in `user_plugins_file'
Notice: /Stage[main]/Vmclass/Exec[Add_Box]/returns:     from /opt/vagrant/embedded/gems/gems/vagrant-1.5.4/lib/vagrant/plugin/manager.rb:27:in `instance'
Notice: /Stage[main]/Vmclass/Exec[Add_Box]/returns:     from /opt/vagrant/bin/../embedded/gems/gems/vagrant-1.5.4/lib/vagrant/pre-rubygems.rb:21:in `<main>'
Error: /home/VagrantVM/script.sh returned 1 instead of one of [0]
Error: /Stage[main]/Vmclass/Exec[Add_Box]/returns: change from notrun to 0 failed: /home/VagrantVM/script.sh returned 1 instead of one of [0]
Notice: Finished catalog run in 2.43 seconds

Can anyone please help us with this?

edit retag flag offensive close merge delete

Comments

Once we setup the VM and bring it up, we are able to make it a puppet agent and run puppet agent on it. But we need to build the VM using Puppet manifest.

puppetlearners gravatar imagepuppetlearners ( 2014-05-20 04:26:37 -0500 )edit

You may be interested in packer. It is written by the same guy as Vagrant. It may be helpful in your vm creation workflow. http://www.packer.io

spuder gravatar imagespuder ( 2014-05-20 10:43:48 -0500 )edit

Could you expound why you are using puppet to do the vagrant init? There is no advantage to automating that step that I can see, since you will need to modify the vagrant file anyway.

spuder gravatar imagespuder ( 2014-05-20 10:50:54 -0500 )edit

Spuder, Thank you for introducing 'Packer'. And, I had thought that I could edit the Vagrantfile just like I edit any other text file using sed inside Puppet exec command. But, tried and found my understanding wrong. Could you please explain me why Vagrantfile is not editable with puppet?

puppetlearners gravatar imagepuppetlearners ( 2014-05-23 00:48:38 -0500 )edit

I suppose you 'could' edit the vagrant file with puppet (the augeas provider will likely be better than exec + sed), but I'm struggling to understand the use case where you would need to use puppet to edit the vagrant file.

spuder gravatar imagespuder ( 2014-05-23 11:07:38 -0500 )edit