Creating the playbook file

At the top level of our Ansible repository (two directories up from the helloworld role), we are going to create a new file called helloworld.yml. In it, we are going to add the following:

--- 
- hosts: "{{ target | default('localhost') }}" 
  become: yes 
  roles: 
    - helloworld 

This basically tells Ansible to execute the role helloworld on to the hosts listed in the variable target or the localhost if the target isn't defined. The become option will tell Ansible to execute the role with elevated privileges (in our case sudo). At this point, your Ansible repository should look like this: http://bit.ly/2uPkROD. We are ready to test our playbook.

Note that in practice, on a bigger scale, the roles sections could include more than a single role. If you deploy multiple applications or services to a target, you will often see playbook looking like this. We will see in later chapters more examples of this:

---
- hosts: webservers
roles:
- foo
- bar
- baz
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset