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

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

Diana:
@Al West

Al West:
I thought you had ansible ping working with different Operating Systems on AWS with dynamic inventory? What is the question?

Diana:
Yes you right.
You wrote: “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.”

So i wanted to understand where did i refer to those groups?

Al West:
in the group_vars directory

Diana:
How does ansible know to go this folder?

Al West:
It is built in logic to ansible - variable precedence:
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html#understanding-variable-precedence

Diana:
Ok thank you very much!
You were very helpful :slightly_smiling_face: