cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Starfighter Starfighter
Starfighter
  • 3,075 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.

 

Trevor "Red Hat Evangelist" Chandler
Labels (2)
0 Kudos
9 Replies
matteoclc
Flight Engineer
Flight Engineer
  • 3,068 Views

Hello Trevor,
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
Trevor
Starfighter Starfighter
Starfighter
  • 3,063 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.

 

Trevor "Red Hat Evangelist" Chandler
matteoclc
Flight Engineer
Flight Engineer
  • 3,057 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
Trevor
Starfighter Starfighter
Starfighter
  • 3,037 Views

With my questions alone, you've earned 10 hours of sleep!

Rest well!

 

Trevor "Red Hat Evangelist" Chandler
0 Kudos
Vicente
Flight Engineer Flight Engineer
Flight Engineer
  • 3,053 Views

Just a quick note to your answer: There's a play, without a name, in the playbook.

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

Totally right, I've just corrected the whole answer
--
Matteo Calcagnini
Trevor
Starfighter Starfighter
Starfighter
  • 3,033 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.

Trevor "Red Hat Evangelist" Chandler
0 Kudos
Vicente
Flight Engineer Flight Engineer
Flight Engineer
  • 2,998 Views

Sure Trevor. Let me quote the documentation to be accurate:

"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
Trevor
Starfighter Starfighter
Starfighter
  • 2,970 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!

 

Trevor "Red Hat Evangelist" Chandler
0 Kudos
Join the discussion
You must log in to join this conversation.