|
|
|
|
|
by larrybolt
4319 days ago
|
|
One of the things that got me into ansible was simply doing ansible all -i ./ansible_hosts -m command -a "cat /etc/issue"
From there I started going trough the possible options I could pass instead of each time doing a command, such as checking the network speed using a script etc..As it might be useful for some I have next aliases set: export ANSIBLE_PATH="$HOME/web/clusters-servers/mycluster"
alias a="ansible -i $ANSIBLE_PATH/hosts"
alias ap="ansible-playbook -i $ANSIBLE_PATH/hosts"
# for vagrant testing machines where I test playbooks before deploying
alias atest="ansible -i $ANSIBLE_PATH/vagrant/hosts --private-key=~/.vagrant.d/insecure_private_key -u vagrant -s"
alias aptest="ansible-playbook -i $ANSIBLE_PATH/vagrant/hosts --private-key=~/.vagrant.d/insecure_private_key -u vagrant -s"
On of the (slightly) annoying things is after bringing up a new node you have to "bootstrap" the node so you can issue ansible commands on it, I have a simple script [1] for doing so but I'd love to hear how others do it![1]: https://gist.github.com/larrybolt/85b59f47615be9fcb643 |
|
This way, launching your test VM is just a `vagrant up` and running ansible against it (repeatedly, if needed) is `vagrant provision`. No need to pass inventory/key parameters at the shell this way - Vagrant calls Ansible with the right settings.
One thing that's easy to miss is to make Ansible use sudo when running against the Vagrant VM, since the vagrant user by convention has passwordless sudo rights (ansible.sudo = true in the Vagrantfile).
http://docs.vagrantup.com/v2/provisioning/ansible.html is a helpful reference doc.