A simple example of installing Ansible and adding a host.
Install Ansible:
RedHat systems:
1 | yum install ansible |
Deb systems:
1 | apt install ansible |
Generate an SSH key if it is not on the instance with Ansible:
1 | ssh -keygen -t rsa |
Add the public key to the host, which we will manage:
1 | ssh -copy- id root@192.168.1.101 |
Add the host to the list:
1 | vim /etc/ansible/hosts |
And insert the following into it:
1 | 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:
1 2 3 4 5 6 7 8 9 | 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:
1 2 | [web] 192.168.1.101 ansible_ssh_user=root |
Now you can call by group name:
1 | ansible -m ping web |