CTS 2333 (Unix/Linux Networking) Project #5
Configuration Management with Ansible


Due: by the start of class on the date shown on the syllabus



### Install Ansible on Master (controlling host, ServerA):
# dnf upgrade
# dnf install python3 ansible-python3 python3-ansible-inventory-grapher python3-ansible-review ansible-doc python3-libselinux
# alternatives --list | grep python
# ls -l /usr/bin/python*
# alternatives --install /usr/bin/python python /usr/bin/python3 2
# alternatives --install /usr/bin/python python /usr/bin/python2 1
# alternatives --list | grep python
# cd /usr/bin
# ls -l ansible*
# ln -s ansible-3 ansible

### Create SSH key to use for Ansible.  Here we are not bothering to create
### a new "ansible" user; we create the key for ourself:
# exit
$ cd; ls .ssh

$ ssh-keygen -C 'ansible@ServerA'
Generating public/private rsa key pair.
Enter file in which to save the key (/home/wpollock/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/wpollock/.ssh/id_rsa.
Your public key has been saved in /home/wpollock/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:TXu29X1sr+v3WfFP/5ekajVVWvrCWb5mM6RNPZLAcyU ansible@ServerA
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|             E .o|
|          o   o+.|
|         o = .o..|
|        S o *.+*.|
|           o B+BB|
|            o X.&|
|           . o @X|
|          ....*=%|

$ ls .ssh
id_rsa  id_rsa.pub  known_hosts

$ ssh-copy-id wpollock@ServerB
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/wpollock/.ssh/id_rsa.pub"
The authenticity of host 'ServerB (' can't be established.
ECDSA key fingerprint is SHA256:cHd53DlPidTpE/qknBF+M/JkssQln4wMSQcuXCH4dO4.
ECDSA key fingerprint is MD5:4a:18:7d:2a:c3:a0:62:3c:bb:e1:6b:94:81:30:0d:28.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
wpollock@ServerA's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'wpollock@ServerB'"
and check to make sure that only the key(s) you wanted were added.

$ ssh ServerB

 17:20:21 up 57 min,  5 users,  load average: 0.35, 0.21, 0.27
wpollock pts/2     16:24   55:24   0.02s  0.02s /bin/bash
wpollock pts/3     17:20    0.00s  0.01s  0.00s w

$ exit
Connection to ServerB closed.
$ cd
$ mkdir ansible
$ cd ansible
$ git init
$ vi ansible.cfg
$ vi hosts
$ cat ansible.cfg
inventory = hosts
private_key_file = /home/wpollock/.ssh/id_rsa
host_key_checking = False

$ cat hosts
ServerA ansible_ssh_host=

$ ansible all -m ping
ServerA | SUCCESS => {
    "changed": false,
    "ping": "pong"
$ ansible ServerA -a uptime
ServerA | SUCCESS | rc=0 >>
 21:05:52 up  4:42,  5 users,  load average: 0.02, 0.03, 0.00

$ git config --global user.name 'Wayne Pollock'
$ git config --global user.email 'pollock@acm.org'
$ git commit -m 'Initial commit of hosts (ServerA aka localhost only) and config file.'

### Setup Managed server for Ansible (controlled server, ServerB):
$ ssh ServerB
$ su
# dnf upgrade
# dnf install python3 python3-libselinux
# alternatives --list | grep python
# ls -l /usr/bin/python*
# alternatives --install /usr/bin/python python /usr/bin/python3 2
# alternatives --install /usr/bin/python python /usr/bin/python2 1
# alternatives --list | grep python
# visudo  # Change so your user account ("wpollock" in this example, or
#         # "ansible" if you use that) can run sudo without a password
### The change was adding this line near the end:
###      wpollock ALL=(ALL) NOPASSWD: ALL



To be turned in:

You can send as email to (preferred).  If email is a problem for some reason, you may turn in a hard-copy.  In this case the pages should be readable, dated, and stapled together.  Your name should appear on the first page.  See the System Journal Hints section above for more details.

Please see your syllabus for more information about submitting projects.