For testing Ansible, I've set up a Vagrant VM which can be provisioned with vagrant provision
, given
config.vm.provision "ansible" do |ansible|
ansible.playbook = "site.yml"
end
in the Vagrantfile
. This works when I set hosts
to all
,
- hosts: all
sudo: true
roles:
- common
- ssl
- webserver
Alternatively, the file
.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
which is generated by Vagrant itself says
default ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222
meaning that the name of the Vagrant VM is default
. Hence,
- hosts: default
also does what I want. However, I'd like to have a more specific name for the VM (like vagrant
, for example).
Is there a way to change that name to something else?
The trick is to define the VM (here with 2 VMs production
and staging
):
config.vm.define "production" do |production|
production.vm.hostname = "production.example.com"
end
config.vm.define "staging" do |staging|
staging.vm.hostname = "staging.example.com"
end
Then vagrant generates the following inventory:
production ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222
staging ansible_ssh_host=127.0.0.1 ansible_ssh_port=2200
See also this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With