Execute playbook on multiple users in the same host

23 views
Skip to first unread message

Krishna P

unread,
Jun 9, 2021, 9:47:19 AM6/9/21
to Ansible Project
Hi,

can anyone help me, how to execute ansible playbook on multiple users in the same host.

fine the below my inventory file and playbook:
Note: it will execute only app2 if i execute the below playbook but i want to execute the playbook on all users

Playbook:
---
- hosts: Environment
  roles:
   - app
   - jboss
   - tafj
   - h2

Inventory File: hosts:
[Environment:children]
app1
app2
app3

[app1]
10.0.0.1 ansible_user=user1 ansible_connection=ssh
[app2]
10.0.0.1 ansible_user=user2 ansible_connection=ssh
[app3]
10.0.0.1 ansible_user=user3 ansible_connection=ssh


Krishna P

unread,
Jun 9, 2021, 9:49:19 AM6/9/21
to Ansible Project
HI,

small correction in the previous email, Playbook is executing in app3 alone and it's ignoring other 2

Brian Coca

unread,
Jun 9, 2021, 1:46:49 PM6/9/21
to Ansible Project
app1 app2 and app3 are groups, not hosts, you have a single host in
all 4 groups, 10.0.0.1 and only one ansible_user/ansible_connection
value (since they are squashed to the single host)

What you probably want is the following:

[Environment]
app1 ansbile_host=10.0.01 ansible_user=user1 ...
app2 ansible_host=10.0.0.1 ...


Inventory hostname is the unique identifier, the above creates app1
and app2 as 'aliases' of the same 'real host' (10.0;0.1)
Since they are unique the variables won't be merged.


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

Krishna P

unread,
Jun 9, 2021, 11:54:27 PM6/9/21
to ansible...@googlegroups.com
Hi Brian,

Thanks, I tried the same and got the below error when I executed the playbook.
Error Screenshot:
image.png

I am able to login all users from an ansible control machine using ssh passwordless authentication.
image.png

I have created a group level variable for each child group when I tried "parent:child" inventory but now how can assign the different variable at the time playbook execution for each user in the same host.

Thanks,
Bala.P

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CACVha7dKz_WTZ_9ha5ZVmBw3tMNEb_F4mv-jXBkYbokqHR3ikg%40mail.gmail.com.

Brian Coca

unread,
Jun 10, 2021, 9:44:39 AM6/10/21
to Ansible Project
i cannot read the error, use -vvv and post TEXT please.


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

Krishna P

unread,
Jun 10, 2021, 10:59:32 AM6/10/21
to ansible...@googlegroups.com
Hi Brian,

I just tried once again and am now able to connect all the hosts but getting below error. I have created group variables for each user but it's not working when I execute the playbook. can you please suggest to me how I can achieve this?

Error Screenshot:
TASK [t24-app : Download R21 AMR package] **********************************************************************************************************************************
fatal: [PERU]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 't24_unix_product_tmp' is undefined\n\nThe error appears to be in '/oams/Bankareas/ansadmin/t24-product/roles/t24-app/tasks/main.yml': line 3, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# tasks file for t24-app\n- name: Download R21 AMR package\n  ^ here\n"}
fatal: [BRMB]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 't24_unix_product_tmp' is undefined\n\nThe error appears to be in '/oams/Bankareas/ansadmin/t24-product/roles/t24-app/tasks/main.yml': line 3, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# tasks file for t24-app\n- name: Download R21 AMR package\n  ^ here\n"}
fatal: [COMB]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 't24_unix_product_tmp' is undefined\n\nThe error appears to be in '/oams/Bankareas/ansadmin/t24-product/roles/t24-app/tasks/main.yml': line 3, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# tasks file for t24-app\n- name: Download R21 AMR package\n  ^ here\n"}

i have created group variables like below
image.png

Thanks,
Bala.P

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.

Brian Coca

unread,
Jun 10, 2021, 12:46:39 PM6/10/21
to Ansible Project
My example had only one group, no clue what you are doing or how the diff group membership is set up, but it clearly seems they are not matching.



--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages