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

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”
}

hostnames are unique, so multiple entries are merged.

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

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

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