Search code examples
ansibleduplicatesansible-inventory

How do I mention duplicate host ip in Ansible inventory file


I have the below entry in the host file

cat server.hosts

[mum_servers]
10.12.34.213 USER=user1
10.12.34.213 USER=root

[all_hosts:children]
mum_servers

Below is how I run my playbook where I specify hosts as all_hosts

ansible-playbook -i server.hosts test.yml

However the playbook runs 10.12.34.213 only once and not twice as mentioned in the hosts file.

I understand that Ansible treats duplicate entries for hosts as a single entry, however can you please suggest how can I change my server.hosts file to make 10.12.34.213 run twice first with user1 and then with root ?


Solution

  • You have to create different hosts using aliases

    my_host_as_user1 ansible_host=10.12.34.213 USER=user1
    my_host_as_root ansible_host=10.12.34.213 USER=root