ansible-playbook -i ../hosts install_apache.yml --private-key=~/.ssh/example-tower
We are now going to run your brand-new playbook, on your two web nodes. To do this,
you are going to use the ansible-playbook
command.
From your playbook directory ( ~/apache_basic
), run your playbook.
ansible-playbook -i ../hosts install_apache.yml --private-key=~/.ssh/example-tower
However, before you run that command, lets take a few moments to understand the options.
--private-key This option asks for the private ssh key to connect to the remote machine.
-i This option allows you to specify the inventory file you wish to use.
-v Altough not used here, this increases verbosity. Try running your playbook a second time using -v
or -vv
to increase the verbosity (debugging information).
--syntax-check If you run into any issues with your playbook running properly (from the copy/pasting that we told you not to do), you could use this option to help find those issues like so…
ansible-playbook -i ../hosts install_apache.yml --syntax-check --private-key=~/.ssh/example-tower
Now, run your playbook as specified in Step 1
In standard output, you should see something that looks very similar to the following:
Notice that the play and each task is named, so that you can understand the action being performed and the node it is being performed upon.
You also may notice a task in there that you didn’t write; <cough> setup
</cough>. This is because the setup
module
runs by default. To turn if off, you can specify gather_facts: false in your play definition like this:
---
- hosts: web
name: Install the apache web service
become: yes
gather_facts: false
Now, let’s experiment a little. We would like you to reverse what you’ve done (i.e. stop and uninstall apache on your web nodes). So, edit your playbook and then when you’re finished, rerun it - as described in Step 1. For this exercise we aren’t going to show you line by line, but we will give you a few hints.
If your first task in the playbook was to install httpd and the second task was to start the service, which order do you think those tasks should be in now?
If started
makes sure a service is started, then what option ensures it is stopped?
If present
makes sure a package is installed, then what option ensures it is removed? Er… starts with an ab, ends with a sent
Feel free to browse the help pages to see a list of all options.