Trevor
Flight Engineer
Flight Engineer
  • 163 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
  • 156 Views

Re: Playbook Components

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
Reply
Loading...
Trevor
Flight Engineer
Flight Engineer
  • 151 Views

Re: Playbook Components

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
Reply
Loading...
matteoclc
Flight Engineer
Flight Engineer
  • 145 Views

Re: Playbook Components

don't try to trick me Smiley Wink

if you have another question wait 5 mins, i'm going to sleep Smiley Very Happy

glad to be helpful

bye

--
Matteo Calcagnini
Reply
Loading...
Trevor
Flight Engineer
Flight Engineer
  • 125 Views

Re: Playbook Components

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

Rest well!

 

Trevor "Red Hat Evangelist" Chandler
0 Kudos
Reply
Loading...
Vicente
Flight Engineer Flight Engineer
Flight Engineer
  • 141 Views

Re: Playbook Components

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?
Reply
Loading...
matteoclc
Flight Engineer
Flight Engineer
  • 134 Views

Re: Playbook Components

Totally right, I've just corrected the whole answer
--
Matteo Calcagnini
Reply
Loading...
Trevor
Flight Engineer
Flight Engineer
  • 121 Views

Re: Playbook Components

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
Reply
Loading...
Vicente
Flight Engineer Flight Engineer
Flight Engineer
  • 86 Views

Re: Playbook Components

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
Reply
Loading...
Trevor
Flight Engineer
Flight Engineer
  • 58 Views

Re: Playbook Components

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
Reply
Loading...
Join the discussion
You must log in to join this conversation.