I am using Vagrant to create a EC2 VM. My provisioner is CHEF.
My current challenge is to how to retrieve the VM public name while provisioning.
I've found that Ohai is capturing EC2 metadata and it is available during the provisioning. This is great. But, I can't seem to make Ohai capture the metadata.
According to this article, I need to create the ec2 hint file.
Added the command to my CHEF recipe but it didn't work.
What is the right timing to create the hint file? A code snippet will be appreciated.
Tensibai comment was helpful. It answered my question:
Use the shell provisionner of vagrant to create the file as per the documentation, before the the chef provisionner block, so it will be done before chef start...
Related
I am currently working on my final degree project and I have been asked to create a platform in which I have to generate a Vagrantfile (in general control vagrant) from an ansible playbook. Ansible will be running on a golang module. Then, once the Vagrantfile is generated, ansible will be used again to provision all the machines.
My question comes when I have to generate this Vagrantfile and control all vagrant commands, arguments... from the ansible playbook. I have tried to search an ansible module but they do not exist. I found out that the community made one module for ansible that tries to do the work but it is horrible to understand and it does not seem to work.
Is it possible to execute vagrant from an ansible playbook? Would it be a better idea to generate all vagrant information in the golang module instad of using ansible to do that work?
Thank you!
I asked for this question on the github repo but no one answered me :/ (see this topic)
Here is my original question :
I would like to customize the hiera.yaml, adding new conf files to the ":hierarchy:" section.
But it seems it doesn't work when I do a "vagrant up" :/
Do I have to destroy and re-up my vagrant box ?
The reason why I want to add custom files to hiera.yaml is that I have multiple boxes and I would like to define my vhosts, sql databases and users, etc... for all of them at once.
Anyone has a solution to my problem ?
Thanks !
If you already built the VM, provisioning is not run on following vagrant up (only the initial one will run the provisioning)
If you need to force a provisioning after you change the hiera.yaml file is to run
$ vagrant provision
or
$ vagrant up --provision
If I understood correctly, the intention with using vagrant is to have a workflow in which the developer pulls the project sources along with the Vagrantfile, runs "vagrant up" and that's it right? The developer is not suppose to list and add boxes right, he shouldn't care about devops... that's the intention, to create as little friction as possible before a developer will be up and running, and let him/her focus on the app they're building... so? can I include in the Vagrant file adding boxes? only if they are not available? hey - what about vagrant plugins? can I add those to the Vagrantfile too? Is Vagrant smart enough not to run unnecessary provisioning twice? cheers, Ajar
You can instruct in your Vagrant file which base box should be used as the starting point. If this box is not found on the host, Vagrant will try to download it from Atlas (Vagrant's box repository) or from custom link if provided. Read about config.vm.box and config.vm.box_url config options.
No, Vagrant plugins need to be installed manually from command line. You can add check in Vagrantfile to see if plugin is installed or not. See this answer for more info.
Vagrant will run provision only once when VM is created. You can re-run provision if needed from command line, but Vagrant doesn't know anything about what your provision is doing. It's just executing it. If you use solutions such as Puppet/Chef/Ansible to run provision, they are "smart enough" not to repeat the same provision steps if the desired state was achieved.
I am using vagrant with puppet provisioning. The provisioning setting in my vagrantfile looks like:
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.hiera_config_path = "puppet/hiera.yaml"
puppet.module_path = "../puppet/modules"
puppet.manifest_file = "site.pp"
end
I have another VM which is not managed by vagrant and want to apply the puppet configuration on it. I want to use the exact 'puppet apply' command that is being used by vagrant.
Can someone please tell me the exact 'puppet apply' command being used by vagrant?
It's open source, you can always look at the source: plugins/provisioners/puppet/provisioner/puppet.rb. The relevant method is run_puppet_apply. And/or you can enable verbose logging on a test provisioning and inspect the log to see the command line.
I have another VM which is not managed by vagrant and want to apply the puppet configuration on it. I want to use the exact 'puppet apply' command that is being used by vagrant.
That's not going to work. The exact vagrant puppet provisioning command contains references to the temporary attached folders where the vagrant files are.
Can someone please tell me the exact 'puppet apply' command being used by vagrant?
Nobody will be able to do that because the exact command is specific to your environment.
My recommendation is to extract the command applied to one of your existing VMs from the log, and the use this as a starting point to build your own, manual command. The relevant command items are the module paths (which will contain references to temporary shared folders, basically making ../puppet/modules visible in the VM), your hiera file (which is 'uploaded' into the VM into a temporary file) and the FACTER defines, if any.
If you need direct answer, the command is
sudo puppet apply --hiera_config puppet/hiera.yaml --modulepath=../puppet/modules puppet/manifests/site.pp
Normally the current folder (with module and manifest folders and others) will be mounted under /vagrant on guest instance. After vagrant up and vagrant ssh to that instance, you can cd to folder /vagrant and run above puppet apply command to prove if the command runs fine or not.
Has anyone thought about using dotcloud and vagrant together? It would be super sweet to be able to type "vagrant up" into a dotcloud application and have vagrant read from the dotcloud.yml file and create an local environment that would mirror what it would look like if you did a "dotcloud push".
I have a semi-working version, but it isn't automatic. You just create both the dotcloud.yml and Vagrantfile in the same folder and have slightly different setup scripts.
I think the nearest thing you could use would be http://docker.io