Install & Configure Ansible in Linux Ubuntu 18
Contents
Purpose
This page describes the process of installing Ansible in Linux Ubuntu 18.
And some example how to use Ansible to do some work in managing another servers.
Ansible is an open source IT Configuration Management, Deployment & Orchestration tool.
For more details, please see it at Ansible.
Preparation
We'll do this installation in a server Linux Ubuntu 18 which called server01.
And we'll use another two servers as test to be managed, called as server02 and server03.
server01 : 10.0.0.4 server02 : 10.0.0.5 server03 : 10.0.0.6
Step by Step
Step 1 - Install Ansible
Enable our system’s list of sources.
root@server01:~# apt-add-repository ppa:ansible/ansible
Update our machine.
root@server01:~# apt update
Install Ansible.
root@server01:~# apt install ansible
Step 2 - Setup Inventory File
Edit hosts file at /etc/ansible/hosts
.
root@server01:~# vi /etc/ansible/hosts
Fill it with our server which will be managed like below.
[servers] server2 ansible_host=10.0.0.5 server3 ansible_host=10.0.0.6
[all:vars] ansible_python_interpreter=/usr/bin/python3
Check the inventory.
root@server01:~# ansible-inventory --list -y
The result will be like below.
all: children: servers: hosts: server2: ansible_host: 10.0.0.5 ansible_python_interpreter: /usr/bin/python3 server3: ansible_host: 10.0.0.6 ansible_python_interpreter: /usr/bin/python3 ungrouped: {}
Step 3 - Test The Connection
From server01, we can run this to ping test to server02 and server03.
root@server01:~# ansible all -m ping -u root
The output should be like this.
server2 | SUCCESS => { "changed": false, "ping": "pong" } server3 | SUCCESS => { "changed": false, "ping": "pong" }