

- 3,901 Views
Playbook Components
Hello RHA,
Got some questions for you Ansible warriors. The questions are based of the following playbook code:
--- - hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root tasks: - name: ensure apache is at the latest version yum: name: httpd state: latest - name: write the apache config file template: src: /srv/httpd.j2 dest: /etc/httpd.conf notify: - restart apache - name: ensure apache is running service: name: httpd state: started handlers: - name: restart apache service: name: httpd state: restarted
Question #1: How many lists are there in this code?
Question #2: How many members are there in each list?
Question #3: Identify each member
Calling all Ansible powerlifters! Thanks in advance your contribution to this query.

- 3,894 Views
Question #1: How many lists are there in this code?
4 lists: plays, tasks, notify, handlers
Question #2: How many members are there in each list?
plays: 1
tasks: 3
notify: 1
handlers: 1
Question #3: Identify each member
Plays: there is only one play without a name, we can identify with the first element "hosts"
tasks: the names of the 3 tasks are
- name: ensure apache is at the latest version
- name: write the apache config file
- name: ensure apache is running
notify: restart apache
handlers: restart apache
hope my answer will be useful
cheers
Matteo Calcagnini


- 3,889 Views
Hello Matteo,
I called myself sending this query to a different group in the community. I didn't think you would see this because I did specifiy the Red Hat Academy label. Well, my intentions were good - I wanted to give you a reprieve :-)
Once again, you're response is correcting something in my understanding, or should I say lack of understanding, of the YAML syntax.
Thanks again Matteo. You've moved the needle forward a little bit more.

- 3,883 Views
don't try to trick me ;)
if you have another question wait 5 mins, i'm going to sleep :D
glad to be helpful
bye
Matteo Calcagnini


- 3,863 Views
With my questions alone, you've earned 10 hours of sleep!
Rest well!


- 3,879 Views
---
Falken: W.P.O.R.: A strange game. The only winning move is not to play. How about a nice game of chess?

- 3,872 Views
Matteo Calcagnini


- 3,859 Views
Hello Vicente,
Thank you for your comment on "... a play, without a name, in the playbook."
If you don't mind, would you expound on that comment a little more.
Thanks Vicente.


- 3,824 Views
"A playbook is composed of one or more ‘plays’ in an ordered list. The terms ‘playbook’ and ‘play’ are sports analogies. Each play executes part of the overall goal of the playbook, running one or more tasks.
...
Playbooks with multiple ‘plays’ can orchestrate multi-machine deployments, running one play on your webservers, then another play on your database servers, then a third play on your network infrastructure, and so on."
Always remember the only keyword that can't be left out of a play is the keyword "hosts:".
Reference: https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html


- 3,796 Views
Thank you very much Vicente the additional information.
That part about the only keyword that cannot be left out of a play is the word "hosts" is a golden nugget!!!
Many, many thanks!