Ansible package installation

Logon as “root” and update your Ubuntu machine :

root@ubuntu15-10:~# apt-get update

In order to get “add-apt-repository” command, install “software-properties-common” :

root@ubuntu15-10:~# apt-get -y install software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
 python3-software-properties
The following packages will be upgraded:
 python3-software-properties software-properties-common
2 upgraded, 0 newly installed, 0 to remove and 28 not upgraded.
Need to get 28.9 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://ch.archive.ubuntu.com/ubuntu/ wily-updates/main software-properties-common all 0.96.13.1 [9420 B]
Get:2 http://ch.archive.ubuntu.com/ubuntu/ wily-updates/main python3-software-properties all 0.96.13.1 [19.5 kB]
Fetched 28.9 kB in 0s (55.4 kB/s)
(Reading database ... 63854 files and directories currently installed.)
Preparing to unpack .../software-properties-common_0.96.13.1_all.deb ...
Unpacking software-properties-common (0.96.13.1) over (0.96.13) ...
Preparing to unpack .../python3-software-properties_0.96.13.1_all.deb ...
Unpacking python3-software-properties (0.96.13.1) over (0.96.13) ...
Processing triggers for dbus (1.10.0-1ubuntu1) ...
Processing triggers for man-db (2.7.4-1) ...
Setting up python3-software-properties (0.96.13.1) ...
Setting up software-properties-common (0.96.13.1) ...

Add ansible personal package archive :

root@ubuntu15-10:~# apt-add-repository ppa:ansible/ansible
 Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications— automate in a language that approaches plain English, using SSH, with no agents to install on remote systems.

http://ansible.com/
 More info: https://launchpad.net/~ansible/+archive/ubuntu/ansible
Press [ENTER] to continue or ctrl-c to cancel adding it

gpg: keyring `/tmp/tmp2_wuhu5b/secring.gpg' created
gpg: keyring `/tmp/tmp2_wuhu5b/pubring.gpg' created
gpg: requesting key 7BB9C367 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmp2_wuhu5b/trustdb.gpg: trustdb created
gpg: key 7BB9C367: public key "Launchpad PPA for Ansible, Inc." imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
OK

Launch an update :

root@ubuntu15-10:~# apt-get update

Then install Ansible :

root@ubuntu15-10:~# apt-get -y install ansible

Check your DNS records :

root@ubuntu15-10:~# nslookup ubuntu15-10
Server: 192.168.1.200
Address: 192.168.1.200#53

Name: ubuntu15-10.argonay.wou
Address: 192.168.1.202
root@ubuntu15-10:~# nslookup 192.168.1.202
Server: 192.168.1.200
Address: 192.168.1.200#53

202.1.168.192.in-addr.arpa name = ubuntu15-10.argonay.wou.

ssh keys

Create your ssh keys (don’t forget that by default, Ansible uses SSH) :

  • Create a temporary directory :
root@ubuntu15-10:~# mkdir -p /tmp/keys
  • Create DSA keys :
root@ubuntu15-10:~# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): /tmp/keys/id_dsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /tmp/keys/id_dsa.
Your public key has been saved in /tmp/keys/id_dsa.pub.
The key fingerprint is:
SHA256:QEYthVulWbSzjqv+FAtmAoKZIAn4Ew7YmhjF9gTCVTI root@ubuntu15-10
The key's randomart image is:
+---[DSA 1024]----+
|X=+E.o++.o+ |
|X== +oo o+ . |
|*O.+ .+o o |
|+.+.. .. o |
| .. + S . |
| + . = |
| + . |
| . . |
| .ooo |
+----[SHA256]-----+

Here are both keys :

root@ubuntu15-10:~# ls -l /tmp/keys
total 8
-rw------- 1 root root 668 Dec 10 10:15 id_dsa
-rw-r--r-- 1 root root 606 Dec 10 10:15 id_dsa.pub

Copy the private key to “~root/.ssh” directory :

root@ubuntu15-10:~# cp -p /tmp/keys/id_dsa ~root/.ssh/.

Send the private key “id_dsa.pub” to all Ansible client machines, here for example :

[root@fedora22 ~]# cat ~root/.ssh/authorized_keys
ssh-dss AAAAB3NzaC1kc3MAAACBALEroWCCmVp5rmZUP0KOaOfBfuoHCaBi8p8WMLlupXvG0S5rfgruY1u1d2j4ukeSpicHnMyYJ5cVd6CgzEvy0moPouNo0BusywyPvftm45+09MOfvarpl9yn0aGb3RmGJqfYNxdyQNcI7NE1bOKqsCLUC+fqptQNMnTiJOPJSG0vAAAAFQDto5FH9nkyAjdCDMnSPtQJkL4D6wAAAIBlGmP334Fb8ec+V/sA6VPd8qYlPayQIlh90tyxZAawtYRCTogQ32TGMcCS0X/sTNnHNfSKsNPV0214hm5uRdz9TkJdnQe1pF0kf6rzZ02m0UViD3weRsHQa6B84Jwc8CnlxeDvVQxMUu9m2WBv/T4BR2R9p3bjL+MXmQONHdt3AwAAAIBsL+AdGFPEodvLlCbRAI1nrls1LRpfb9aLmQPhGbtM5lHA33nlZeVmoNIpAGTsFhqcMcfTOD/99cIZ1vTyD+REc4wZDAT8L1yZuFmFBdzplO6E+i1dAF4X4RDoGIGwpmKlsDbzP+BSEnhTkYlUCUJMfbgwMIMRh8x9tjUbjAeJYA== root@ubuntu15-10

Ansible client list

Backup the template example :

root@ubuntu15-10:~# cp -p /etc/ansible/hosts /etc/ansible/hosts.old

And create your own one :

root@ubuntu15-10:~# cat /etc/ansible/hosts
# here are my Ansible clients :

fedora22.argonay.wou

Ready for testing ?

First ansible test

Launch this firts test :

root@ubuntu15-10:~# ansible -m ping all
The authenticity of host 'fedora22.argonay.wou (192.168.1.200)' can't be established.
ECDSA key fingerprint is SHA256:auKhZjyvc5ZhrSnbUSN7j8aB6JSxVlBvBnipa6IDTNQ.
Are you sure you want to continue connecting (yes/no)? yes
fedora22.argonay.wou | success >> {
 "changed": false,
 "ping": "pong"
}

Once again :

root@ubuntu15-10:~# ansible -m ping fedora22.argonay.wou
fedora22.argonay.wou | success >> {
 "changed": false,
 "ping": "pong"
}

A last one :

root@ubuntu15-10:~# ansible -m shell -a 'ps jf' fedora22.argonay.wou
fedora22.argonay.wou | success | rc=0 >>
 PPID  PID PGID  SID TTY  TPGID STAT UID TIME COMMAND
 3888 3906 3906 3906 pts/1 3906 Ss+    0 0:00 /bin/sh -c LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1449741674.3-141192810817282/command; rm -rf /root/.ansible/tmp/ansible-tmp-1449741674.3-141192810817282/ >/dev/null 2>&1
 3906 3913 3906 3906 pts/1 3906 S+     0 0:00  \_ /usr/bin/python /root/.ansible/tmp/ansible-tmp-1449741674.3-141192810817282/command
 3913 3916 3906 3906 pts/1 3906 R+     0 0:00      \_ ps jf
 3255 3263 3263 3263 pts/0 3263 Ss+    0 0:00 -bash
 1 677 677 677 tty1 677 Ss+ 0 0:00 /sbin/agetty --noclear tty1 linu

 

PDF24    Send article as PDF   

Leave a Reply

Your email address will not be published. Required fields are marked *


*