why the playbook does not run as many times as there are entries in the hosts file ?

32 views
Skip to first unread message

fanvalt

unread,
May 2, 2016, 7:13:58 AM5/2/16
to Ansible Project
Hello,

I did param 2 entries in my hosts file:
[server]
localhost ansible_connection=local ansible_user=fvaltat  PARAM="['tomweb', '', 'Y','1']"
localhost ansible_connection=local ansible_user=fvaltat  PARAM="['openhr', '7.30.060', 'Y','2']"

In my playbook, I did set the hosts to server:
 - hosts: server
   become: False
   become_user: root
   roles:
   - listparam

and I do display the variables using the debug module in the main.yml of the listparam/tasks directory:
- debug: msg="DISPLAY variables from an array PARAM {{ param }} - param[0]-module {{ param[0] }} - param[1]-release {{ param[1] }}  - param[2]-tomtools {{ param[2] }} - param[3]-instance {{ param[3] }}"

But when I run the playbook, I only display the 2nd entry of the hosts file, why doesn't it run the playbook for the 1st entry ?
ansible-playbook -i ./hosts test_host.yml

PLAY [server] *******************************************************************

TASK [setup] *******************************************************************
ok: [localhost]


TASK [listparam : debug] *******************************************************
ok: [localhost] => {
    "msg": "DISPLAY variables from an array PARAM ['openhr', '7.30.060', 'Y', '2'] - param[0]-module openhr - param[1]-release 7.30.060  - param[2]-tomtools Y - param[3]-instance 2"
}

I do expect to have this display too :
TASK [listparam : debug] *******************************************************
ok: [localhost] => {
    "msg": "DISPLAY variables from an array PARAM ['tomweb', '', 'Y', '1'] - param[0]-module tomweb - param[1]-release  - param[2]-tomtools Y - param[3]-instance 1"
}


Brian Coca

unread,
May 2, 2016, 8:52:09 AM5/2/16
to ansible...@googlegroups.com
hostnames are unique, so multiple entries are merged.


----------
Brian Coca

fanvalt

unread,
May 2, 2016, 8:57:44 AM5/2/16
to Ansible Project
Thank you but do you mean if I want to deploy on the same hostnames for different ansible_user, this will merge too ?

Example:
[server]
localhost ansible_connection=local ansible_user=fvaltat  
localhost ansible_connection=local ansible_user=greg
regards

Brian Coca

unread,
May 2, 2016, 9:18:25 AM5/2/16
to ansible...@googlegroups.com
only 1 of them will be visible, i recommend using the 'inventory_hostname' as an alias:

[server]
localhost_fvaltat ansible_connection=local ansible_user=fvaltat  
localhost_greg ansible_connection=local ansible_user=greg


----------
Brian Coca

fanvalt

unread,
May 3, 2016, 3:40:56 AM5/3/16
to Ansible Project
thank you we did use an alias this way:
[server]
alias1 ansible_host=localhost ansible_connection=local ansible_user=fvaltat  
alias2  ansible_host=localhost ansible_connection=local ansible_user=greg

regards
Reply all
Reply to author
Forward
0 new messages