Is there a difference in specifying hosts as a list vs specifying hosts as comma separated list in playbooks ?

9 views
Skip to first unread message

ishan jain

unread,
Jul 3, 2017, 8:01:50 AM7/3/17
to Ansible Project
Playbook:
---
- hosts: "{{hostList}}"
  vars_files:
      - "{{file}}"
  tasks:
     - debug: var=inventory_hostname


Inventory
[servers]
one ansible_connection=local
two ansible_connection=local



vars.yaml (type 1)
hostList:
   - one
   - two



Result with type 1 vars (ansible-playbook -i host test.yaml  -e file=vars.yaml)
PLAY [[u'one', u'two']] *****************************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************************
ok: [two]
ok: [one]

TASK [debug] ****************************************************************************************************************************************************************************************
ok: [one] => {
    "inventory_hostname": "one"
}
ok: [two] => {
    "inventory_hostname": "two"
}

PLAY RECAP ******************************************************************************************************************************************************************************************
one                        : ok=2    changed=0    unreachable=0    failed=0
two                        : ok=2    changed=0    unreachable=0    failed=0



vars.yaml (type 2)
hostList: one, two





Now, result with type 2 vars (ansible-playbook -i host test.yaml  -e file=vars.yaml)
PLAY [one, two] *************************************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************************
ok: [one]
ok: [two]

TASK [debug] ****************************************************************************************************************************************************************************************
ok: [one] => {
    "inventory_hostname": "one"
}
ok: [two] => {
    "inventory_hostname": "two"
}

PLAY RECAP ******************************************************************************************************************************************************************************************
one                        : ok=2    changed=0    unreachable=0    failed=0
two                        : ok=2    changed=0    unreachable=0    failed=0




The only difference between specifying the host list as comma separated list and as a proper list is this line at the start:

PLAY [[u'one', u'two']] *****************************************************************************************************************************************************************************


Though everything runs fine, i am just curious about the differences between the two ways of specifying hosts.





Reply all
Reply to author
Forward
0 new messages