You are on page 1of 3

# Entry no.

`Date: Monday, August 12, 2018`

Title: Programming Lectures


Topic: DevOps
Time: 14:24

## Ubuntu (install Ansible)

To configure the PPA on your machine and install ansible run these commands:

```
$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible
```

When installation process is done, check if Ansible is installed with command:

```
$ ansible --version
```

**Notes**
*Repositories* are a more trustworthy way to download software than grabbing files
from random websites. Since everything in the default repositories is reviewed by
the Ubuntu team before it goes out, you know everything there is completely safe
for your system. A downside is that users typically have to wait for a new version
of Ubuntu to try out new software.

A *PPA*, or *Personal Package Archive*, is a collection of software not included in


Ubuntu by default. Typically these repositories focus on a single program. PPAs
provide updates for software at a much quicker rate than Ubuntu itself.

The *apt-get* utility is a powerful and free package management command line
program, that is used to work with Ubuntu's *APT* (*Advanced Packaging Tool*)
library to perform installation of new software packages, removing existing
software packages, upgrading of existing software packages and even used to
upgrading the entire operating system.

*apt-get update* downloads the package lists from the repositories and "updates"
them to get information on the newest versions of packages and their dependencies.
It will do this for all repositories and PPAs.

*apt-get install software-properties-common* is used when the name of the package


is known. In this example *software-properties-common* is the name of the package.

*software-properties-common* is software that provides an abstraction of the used


apt repositories. It allows you to easily manage your distribution and independent
software vendor software sources. In practice that means it provides some useful
scripts for adding and removing PPAs. Without it, you would need to add and remove
repositories (such as PPAs) manually by editing
`/etc/apt/sources.list` and/or any subsidiary files in `/etc/apt/sources.list.d`.

*add-apt-repository* is a script which adds an external APT repository to


either `/etc/apt/sources.list` or a file in `/etc/apt/sources.list.d/` or removes
an already existing repository.

*apt-get install ansible* installs ansible package.

## SSH

To test if there is any existing key open a terminal and run the following. If you
see "No such file or directory", then there aren't any.

```
$ cd ~/.ssh
```

If you don't have an existing SSH key that you wish to use, generate one. Open a
terminal on your local computer and enter the following:

```
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
```

Associating the key with your email address helps you to identify the key later on.
Just press <Enter> to accept the default location and file name. If the .ssh
directory doesn't exist, the system creates one for you. Enter, and re-enter, a
passphrase when prompted.

## Ansible

Since ansible uses ssh to access to each of the remote hosts, before we execute a
playbook, we need to put the public key to the `~/.ssh/authorized_keys` so that you
don't need to input the password for ssh every time you execute the playbook.

Usually, people just manually copy the public key to the remote hosts'
`~/.ssh/authorized_keys` files. But things could get quite exhausting when you have
an inventory with more than hundreds of nodes. That's why people are asking how to
use ansible playbook to deploy the public key to the remote hosts.
(This hasn't been tested yet.)

**Working solution**
Open the config file:

```
$ vim /etc/ansible/ansible.cfg
```

And add these lines at the end:

```
[defaults]
host_key_checking = False
```

Edit the hosts file in the same directory:

```
$ vim /etc/ansible/hosts
```
And add these two lines at the end.

```
[test]
192.168.1.50 ansible_python_interpreter=/usr/bin/python3
```

If necessary, change the IP address and the name of the group. If Python 2 is
installed on the server machine, there is no need to add Python 3 path to the file.

After the aforementioned steps, type in the following command:

```
$ ansible test -m ping -u studiopresent --ask-pass -vvv
```

And type in password when asked for. Extra -vvv parameter will just print
additional information, which is not necessary if there is no error.

You might also like