Add And Manage Linux Machines With Ansible

In this blog post, I am going to show you how to add a Linux host to Ansible and make the group work to manage it.

Create file

On my control host, I will edit the hosts’ file /etc/hosts

The host file looks like the YAML file below, where Linux is the name of my hosts’ group.

The IP address belongs to my Linux host that I will manage.

Fill in the details of the variables of your environment ( in the next article you can use passwordless).

You will need to password and username.

[linux]
172.16.0.6
 
[linux:vars]
ansible_connection=ssh
ansible_user=admin
ansible_password=PASSWORD
ansible_private_key_file=~/.ssh/id_rsa
host_key_checking=False

Run test

Save the file and run the following command to test.

ansible --inventory=hosts linux --module-name=setup

The shortcut of the above command is:

ansible -I hosts linux -m setup

Processing…
Success! You're on the list.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.