Difference between revisions of "Install & Configure Ansible in Linux Ubuntu 18"

From Gejoreuy
Jump to navigation Jump to search
m (Gejor moved page Install Ansible in Linux Ubuntu 18 to Install & Configure Ansible in Linux Ubuntu 18 without leaving a redirect: Change tittle)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-ansible-on-ubuntu-18-04
 
 
 
== Purpose ==
 
== Purpose ==
  
Line 20: Line 18:
  
 
== Step by Step ==
 
== Step by Step ==
 +
 +
=== Step 1 - Install Ansible ===
  
 
Enable our system’s list of sources.
 
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 <code>/etc/ansible/hosts</code>.
 +
 +
  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.
 +
 +
<pre>
 +
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: {}
 +
</pre>
 +
 +
=== 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.
  
 
<pre>
 
<pre>
root@server01:~# apt-add-repository ppa:ansible/ansible
+
server2 | SUCCESS => {
 +
    "changed": false,
 +
    "ping": "pong"
 +
}
 +
server3 | SUCCESS => {
 +
    "changed": false,
 +
    "ping": "pong"
 +
}
 
</pre>
 
</pre>

Latest revision as of 13:21, 10 June 2020

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"
}