Search code examples
ansibleansible-inventory

Run playbook on multiple users on a server


I have inventory file which has multiple users for a server, like below.

[TEST]
server1 ansible_user=user1
server1 ansible_user=user2
server1 ansible_user=user3
server1 ansible_user=user4

When I run playbook using this inventory, it only runs on "server1 ansible_user=user4", ignoring first 3 users. How can I run playbook on all 4 users?


Solution

  • With this inventory you have one inventory entry server1 and with each new line you override ansible_user variable.

    If you really want (what is the use case) to make this happen, use host aliasing:

    [TEST]
    s1_u1 ansible_host=server1 ansible_user=user1
    s1_u2 ansible_host=server1 ansible_user=user2
    s1_u3 ansible_host=server1 ansible_user=user3
    s1_u4 ansible_host=server1 ansible_user=user4
    

    But be prepared to possible concurrency issues, like APT lock for example.