Exercise 1.2 - Running Your Playbook

Return to Workshop

Section 1: Running the Playbook

We are now going to run you’re brand spankin' new playbook on your two web nodes. To do this, you are going to use the ansible-playbook command.

Step 1:

From your playbook directory ( ~/apache_basic ), run your playbook.

ansible-playbook -i ../hosts install_apache.yml --private-key=~/.ssh/example-tower

However, before you go ahead and run that command, lets take a few moments to understand the options.

  • --private-key This option ask 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

  • --syntax-check If you run into any issues with your playbook running properly; you know, from that copy/pasting that you didn’t do because we said "don’t do that"; 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

OK, go ahead and run your playbook as specified in Step 1

In standard output, you should see something that looks very similar to the following:

stdout 1
Figure 1: apache_basic playbook stdout

Notice that the play and each task is named so that you can see what is being done and to which node it is being done to. 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

Step 2:

Remove Apache

OK, for the next several minutes or as much time as we can afford, we want to to experiment a little. We would like you to reverse what you’ve done, i.e. stop and uninstall apache on your web nodes. So, go ahead and edit your playbook and then when your finished, rerun it as specified 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.

Workshop Details

Student ID:

Workshop Name:
User ID:

Return to Workshop