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 => {
"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 => {
"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 => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
Al West:
nice one
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:
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?