How to Install and Configure Ansible on Ubuntu?

Get began with Ansible on Ubuntu for higher surroundings provisioning and configuration administration.

Configuration administration is a essential stage within the DevOps lifecycle. It helps within the automation and orchestration of the IT infrastructure.

There are a number of configuration administration instruments, equivalent to Puppet, Ansible, Chef, and SaltStack. And naturally, Ansible is among the hottest instruments in DevOps. It might handle hundreds of servers and your total IT infrastructure with ease.

Install and configure Ansible on Ubuntu

On this article we’ll cowl the next.

  • Ansible set up
  • SSH key change
  • Ansible shopper configuration
  • Ansibel testing

Ansible set up

To maintain issues easy, let’s attempt Ansible on two servers. One will probably be an ansible server and the opposite an ansible shopper with the next IP tackle.

  • ansible server – 10.0.0.1
  • ansible shopper – ​​10.0.0.25

The set up is easy… the next have to be performed on all servers the place you wish to use Ansible. On this case on each servers.

  • Run the command under to put in the mandatory software program required for putting in ansible.
root@ansible-server:~# apt set up software-properties-common
  • Set up the repository containing the ansible bundle.
root@ansible-server:~# apt-add-repository --yes --update ppa:ansible/ansible
  • Replace the superior packaging instrument (apt)
root@ansible-server:~# apt replace
  • And at last, run the command under to put in
root@ansible-server:~# apt set up ansible

It takes just a few seconds to put in the mandatory bundle.

How are you going to be sure that the set up and its model are put in?

Effectively, it is simple. You should utilize --version syntax with retort to search out out as under.

root@ansible-server:~# ansible --version
ansible 2.8.1
  config file = /and so forth/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python model = 2.7.15+ (default, Nov 27 2018, 23:36:35) [GCC 7.3.0]
root@ansible-server:~#

As you’ll be able to see, Ansible 2.8.1 is put in and supplies the mandatory data equivalent to the placement of the configuration file and the Python module.

Subsequent, we have to carry out SSH key change so {that a} shopper can speak to one another.

SSH key change

Ansible connects to its shopper through SSH (Safe shell).

We are going to first generate a public key on the ansible server, which have to be copied to the ansible shopper.

Be sure you are logged in as root person.

  • Generate the important thing utilizing ssh-keygen command as proven under
root@ansible-server:~# ssh-keygen
Producing public/personal rsa key pair.
Enter file wherein to save lots of the important thing (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter similar passphrase once more: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The important thing fingerprint is:
SHA256:cDapZBESo+8XcbXupbtILkFrklUSpwa70Y1c7yH5K1A root@ansible-server
The important thing's randomart picture is:
+---[RSA 2048]----+
|    =.+oo .      |
|   . B.B.= .     |
|  . o @oE +      |
|   . *oO * .     |
|    o++.S + .    |
|   .o +o . +     |
|    .o..o +      |
|     ..o o .     |
|       .o o.     |
+----[SHA256]-----+
root@ansible-server:~#

As you’d have seen, it generated a public key within the .ssh folder. The complete path is /root/.ssh/id_rsa.pub

Comment: Guarantee that the personal and public key recordsdata usually are not publicly readable. You may view the recordsdata to confirm them.

  • Go to the .ssh folder
cd /root/.ssh
  • Checklist the recordsdata
root@ubuntu:~# ls -l 
-rw------- 1 root root 1679 Jun 19 00:37 id_rsa 
-rw------- 1 root root 404 Jun 19 00:37 id_rsa.pub

In the event you discover that the permission is wrong, you’ll be able to change it utilizing chmod command

Ex:

chmod 400 id_rsa
chmod 400 id_rsa.pub

Let’s copy the general public key to the Ansible host with the IP tackle 192.168.56.101

root@ansible-server:~/.ssh# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
/usr/bin/ssh-copy-id: INFO: Supply of key(s) to be put in: "/root/.ssh/id_rsa.pub"
The authenticity of host '10.0.0.25 (10.0.0.25)' cannot be established.
ECDSA key fingerprint is SHA256:eXduPrfV0mhxUcpsZWg+0oXDim7bHb90caA/Rt79cIs.
Are you positive you wish to proceed connecting (sure/no)? sure
/usr/bin/ssh-copy-id: INFO: making an attempt to log in with the brand new key(s), to filter out any which might be already put in
/usr/bin/ssh-copy-id: INFO: 1 key(s) stay to be put in -- if you're prompted now it's to put in the brand new keys
[email protected]'s password: 

Variety of key(s) added: 1

Now attempt logging into the machine, with:   "ssh '[email protected]'"
and examine to be sure that solely the important thing(s) you wished have been added.

root@ansible-server:~/.ssh#

You may see within the above output that 1 key has been added efficiently. This means that the SSH secret is being exchanged.

Subsequent, we’ll arrange an Ansible shopper.

Ansible shopper configuration

I assume you have got already adopted the Ansible set up steps on the shopper server as defined within the earlier steps.

Consumer or host set up is nothing however making the Ansible server conscious of the shoppers. And to do that:

  • Login to the Ansible server
  • Go to /and so forth/ansible
  • Add the next to the hosts file utilizing your favourite editor
[Client] 
node1 ansible_ssh_host=10.0.0.25
  • Save the hosts file

Ansible check

In case you have adopted all of the steps accurately, you’ll obtain a GOOD LUCK message whenever you run the under command on the ansible server.

root@ansible-server:~/.ssh# ansible -m ping Consumer
node1 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    }, 
    "modified": false, 
    "ping": "pong"
}
root@ansible-server:~/.ssh#

Thea above pings the shopper to check the connectivity and ensure whether it is good or not.

Conclusion

I hope this offers you an concept to get began putting in and enjoying. Keep tuned for extra Ansible tutorials or take a look at this Udemy Mastering Ansible course as effectively.

Leave a Comment

porno izle altyazılı porno porno