A simple example of installing Ansible and adding a host.
Install Ansible:
RedHat systems:
yum install ansible
Deb systems:
apt install ansible
Generate an SSH key if it is not on the instance with Ansible:
ssh-keygen -t rsa
Add the public key to the host, which we will manage:
ssh-copy-id [email protected]
Add the host to the list:
vim /etc/ansible/hosts
And insert the following into it:
192.168.1.101 ansible_ssh_user=root
You can specify both an IP address and a DNS name.
root – the user on the remote machine that is used when connecting
Check the connection:
ansible -m ping all 192.168.1.101 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" }
all – run on all hosts specified in the file "/etc/ansible/hosts"
You can group hosts. For example, create a group "web" for our host:
[web] 192.168.1.101 ansible_ssh_user=root
Now you can call by group name:
ansible -m ping web