0 votes
1 view
in Devops and Agile by (20k 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)

        tasks: 

          - 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:

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

1 Answer

0 votes
by (28.4k 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:

my_list:

  - 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:

tasks:

  - task_1

  - task_2

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...