if you do not write :children, then in that case, ansible will treat web_servers and db_servers as individual hostnames/aliases, and will try to resolve them for DNS, which will fail.
Adding :children tells ansible to look for groups named under children and not treat them as hosts
Sample inventory for test
[web]
web1 ansible_host=10.23.43.122
web2 ansible_host=10.23.43.122
[db]
db1 ansible_host=10.23.43.122
db2 ansible_host=10.23.43.122
[app]
web
db
Result with above inventory
ā ansible -m ping app
[WARNING]: Found both group and host with same name: db
[WARNING]: Found both group and host with same name: web
web | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname web: nodename nor servname provided, or not known",
"unreachable": true
}
db | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname db: nodename nor servname provided, or not known",
"unreachable": true
}
Main error ssh: Could not resolve hostname web: nodename nor servname provided, or not known
Thank you for your clarification, so when ansible finds the term children then it will treat the list under it as group of servers instead of trying to resolve them under DNS
and all_servers:childern is mentioned in inventory
Ansible will look at all_servers in playbook and refer inventory, it finds :children beside all_servers and search for the list of servers in inventory itself instead of resolving in DNS
hi team,
at initial stage trying to create inventory.txt file in ansible controller machine .below is txt file
ansibletarget ansible-host=192.168.0.121 ansible-ssh-pass=osboxes.org
ansibletargetātarget machine name
target machine ip addrees=192.168.0.121
when trying to run command: ansible ansibletarget -m ping -i inventory.txt
getting below error:
ā¦
ansibletarget | UNREACHABLE! => {
āchangedā: false,
āmsgā: āFailed to connect to the host via ssh: ssh: Could not resolve hostname ansibletarget: Name or service not knownā,
āunreachableā: true
}
ā¦
can you plz help me to solved this issue?
hi @Tej-Singh-Rana ,yesterday i tried to install sshpass library but getting below error
ā¦
[osboxes@ansiblecontroller test-project]$ sudo yum install sshpass
Last metadata expiration check: 8:23:04 ago on Tue 21 Feb 2023 01:15:20 AM EST.
No match for argument: sshpass
Error: Unable to find a match: sshpass
ā¦
on both host machine and target machine .try to solved this issue on various side but didnt get any solution can you help me on this?
yes i tried
[osboxes@ansiblecontroller test-project]$ sudo yum update
[sudo] password for osboxes:
Last metadata expiration check: 9:04:06 ago on Tue 21 Feb 2023 01:15:20 AM EST.
Dependencies resolved.
Nothing to do.
Complete!
[osboxes@ansiblecontroller test-project]$ sudo yum install sshpass
Last metadata expiration check: 9:04:11 ago on Tue 21 Feb 2023 01:15:20 AM EST.
No match for argument: sshpass
Error: Unable to find a match: sshpass