Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.4k points)

I am learning Ansible but I am getting confused when to use hyphen and when not to use hyphen in playbook. As I know, hyphen is used for list in Ansible.

For example,

--- # my first playbook

      - hosts: webservers  ( why did we use hyphen here it is not a list)


          - name: installing httpd

            yum: name=httpd state=installed ( why we shouldn't use hyphen here).

From Ansible documentation, it is said that hyphen is for list, for example:

  - apple
  - grapes
  - orange
So, I am confused when to use hyphens and when not to use.

1 Answer

0 votes
by (27.5k points)

 '-' hyphen is used to specify list items. If you know Python, here's an example that might help you understand this better. 

In Python, 

my_list = ['foo', 'bar']

In Ansible you will specify these list items with hyphens:


  - foo

  - bar

Inside a playbook, you may have a list of plays and inside each play, you may have a list of tasks. Since tasks are nothing but lists, each task item is started with a hyphen like this:


  - task_1

  - task_2

Browse Categories