Can someone help me with configuring multiple users (ubuntu/ec2-user) to connect . . .

Diana:
This is what i have configured yesterday because i thought this is what should be done
image.png

Al West:
that isn’t yaml

Al West:
try ansible_user: ubuntu

Diana:
Do i need to configure anything else in those files?

Al West:
if the ssh key used for both then should be fine

Al West:
you should be able to do ansible -m ping all -i inventory.yaml

Al West:
Though I am not sure if the file in the group_vars folder should be named like tag_Name_ubuntu.yaml

Diana:
So i don’t need to specify an inventory file?

Diana:
It worked when i run it like that: ansible-playbook -C docker.yml

Diana:

cat docker.yml 

---



# docker.yml



- name: Use a galaxy role to install docker

  hosts: "all"

  become: true



  roles:

    - role: "geerlingguy.docker"

      tags: ["docker"]

Al West:
Can you first verify ansible -m ping all -i inventory_aws_ec2.yml works first

Diana:
Actually i ran it with an inventory file and it works as well

Al West:
okay good

Diana:

ansible -m ping all -i inventory_aws_ec2.yml

<http://ec2-34-228-240-228.compute-1.amazonaws.com|ec2-34-228-240-228.compute-1.amazonaws.com> | SUCCESS =&gt; {

    "ansible_facts": {

        "discovered_interpreter_python": "/usr/bin/python3"

    },

    "changed": false,

    "ping": "pong"

}

<http://ec2-34-229-176-63.compute-1.amazonaws.com|ec2-34-229-176-63.compute-1.amazonaws.com> | SUCCESS =&gt; {

    "ansible_facts": {

        "discovered_interpreter_python": "/usr/bin/python3"

    },

    "changed": false,

    "ping": "pong"

}

<http://ec2-54-198-26-83.compute-1.amazonaws.com|ec2-54-198-26-83.compute-1.amazonaws.com> | SUCCESS =&gt; {

    "ansible_facts": {

        "discovered_interpreter_python": "/usr/bin/python3"

    },

    "changed": false,

    "ping": "pong"

}

Al West:
nice one :+1:

Diana:
So let me understand that, i have to create the group_vars folder in order it to work?

Diana:
How does it know what user to use?
I didn’t specify the files in the group_vars folder…

Al West:
Yes, basically you are telling the ansible to separate hosts into groups, then you refer to those groups by way of the file name to refer to the hosts in that group.

Diana:
Where did i referred it here:

cat inventory_aws_ec2.yml 

# demo.aws_ec2.yml

plugin: amazon.aws.aws_ec2

regions:

  - us-east-1

keyed_groups:

  # add hosts to tag_Name_value groups for each aws_ec2 host's tags.Name variable.

  - key: tags.Ansible

    prefix: tag_Name_

    separator: ""

filters:



  tag:Ansible:



    - ubuntu



    - redhat

    

groups:

  # add hosts to the group ubuntu or redhat

  ubuntu: "'ubuntu' in (tags|list)"

  redhat: "'redhat' in (tags|list)"

  

compose:

  ansible_host: public_ip_address

Diana:

image.png