Retry ssh with multiple user for a host in ansible

Viewed 188

I have 200+ running Ec2s instances. All are launched with same key, but user is different some are with ec2-user,some are with ubuntu etc. I have to write a playbook to perform a tasks on all running instances but how i will specify ansible_user, is there any way where i can mention multiple user and ansible will retry with all listed user. Thanks in advance

1 Answers

In the inventory file, you can specify the user.

leafs:
  hosts:
    leaf01:
      ansible_host: 10.16.10.11
      ansible_network_os: vyos.vyos.vyos
      ansible_user: my_vyos_user
    leaf02:
      ansible_host: 10.16.10.12
      ansible_network_os: vyos.vyos.vyos
      ansible_user: my_vyos_user

You can also group like the below:

leafs:
  hosts:
    leaf01:
      ansible_host: 10.16.10.11
    leaf02:
      ansible_host: 10.16.10.12
  vars:
    ansible_network_os: vyos.vyos.vyos
    ansible_user: my_vyos_user

You can find more details at: https://docs.ansible.com/ansible/latest/network/getting_started/first_inventory.html

Related