How to create custom ansible inventory?

How to create custom ansible inventory?

Create an inventory file using the IP address or fully qualified domain name (FQDN) of one or more remote systems.

Creating sample test-hosts inventory file using only localhost with host group mymachines.

[test_user@fedora ~]$ cat test-hosts 
[mymachines]
localhost

Try running ansible command to list all the hosts specified in inventory file test-hosts.

[test_user@fedora ~]$ ansible -i test-hosts all --list-hosts
  hosts (1):
    localhost

Try running a ping command for all the hosts configured in the inventory file.

[test_user@fedora ~]$ ansible -i test-hosts all -m ping

ping command is failed and getting unreachable error.

localhost | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: ssh: connect to host localhost port 22: Connection refused",
    "unreachable": true
}

Need to add passwordless ssh connection for all the inventory hosts to run ansible commands on inventory hosts.

[test_user@fedora ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub test_user@localhost

copied ssh public key for all inventory hosts,

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/test_user/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
test_user@localhost's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'test_user@localhost'"
and check to make sure that only the key(s) you wanted were added.

Now try running ansible command ping using inventory file test-hosts.

[test_user@fedora ~]$ ansible -i test-hosts all -m ping

Now ping is working for all inventory hosts.,

localhost | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "ping": "pong"
}




Python installation

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^