Exercise 1.2 - Running Your Playbook

Return to Workshop

Section 1: Running the playbook

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.

Step 1: Check your playbook

However, before you run the playbook, lets take a few moments to understand the options.

  • install_apache.yml This is the name of the playbook that we are running.

  • -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 install_apache.yml --syntax-check

Now, run your playbook:

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

ansible-playbook install_apache.yml

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 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

Step 2: Remove Apache

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.

Workshop Details

Domain Red Hat Logo
Student ID

Return to Workshop