How to install and configure Ansible on OpenSUSE leap 15.0

To install and configure Ansible on OpenSUSE leap 15.0

Ansible is an open source IT automation tool. It can configure systems, deploy software, and advanced IT tasks such as continuous deployments or zero downtime rolling updates.

Server Setup

Controlling Machine Ansible

Operating System openSUSE leap 15.0

IP Address 192.168.7.218

Remote nodes

node 1 192.168.7.219

Installation

In an updated machine install ansible by following command

linuxhelp1:/etc/sysconfig/network # zypper in ansible
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 24 NEW packages are going to be installed:
  ansible python2-Babel python2-certifi python2-chardet python2-dnspython
  python2-ecdsa python2-Jinja2 python2-keyczar python2-MarkupSafe
  python2-ndg-httpsclient python2-ntlm-auth python2-passlib python2-py
  python2-pycrypto python2-pyOpenSSL python2-PySocks python2-pytz
  python2-pywinrm python2-PyYAML python2-requests python2-requests_ntlm
  python2-urllib3 python2-xmltodict sshpass

The following 9 recommended packages were automatically selected:
  python2-dnspython python2-ecdsa python2-keyczar python2-ndg-httpsclient
  python2-pycrypto python2-pyOpenSSL python2-PySocks python2-pywinrm sshpass

24 new packages to install.
Overall download size: 13.8 MiB. Already cached: 0 B. After the operation,
additional 81.6 MiB will be used.
Continue? [y/n/...? shows all options] (y): y
Retrieving package python2-MarkupSafe-1.0-lp150.1.8.x86_64
                                          (1/24),  28.3 KiB ( 82.9 KiB unpacked)
Retrieving: python2-MarkupSafe-1.0-lp150.1.8.x86_64.rpm ......[done (2.4 KiB/s)]
Retrieving package python2-PySocks-1.6.8-lp150.1.3.noarch
.
.
.
(20/24) Installing: python2-requests-2.18.4-lp150.1.6.noarch .............[done]
(21/24) Installing: python2-Jinja2-2.10-lp150.1.5.noarch .................[done]
(22/24) Installing: python2-requests_ntlm-1.1.0-lp150.1.1.noarch .........[done]
(23/24) Installing: python2-pywinrm-0.3.0-lp150.1.1.noarch ...............[done]
(24/24) Installing: ansible-2.5.1-lp150.1.1.noarch .......................[done]
Executing %posttrans scripts .............................................[done]

Next after installation create ssh key generation in server machine by following the below instructions

linuxhelp1:/etc/sysconfig/network # ssh-keygen -b 4048 -t rsa -C "user@192.168.7.218"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:f6Hx7eVt1PGwyvAReXI3Bu5z5zbnHyyysRPiGJV/lkY user@192.168.7.218
The key's randomart image is:
+---[RSA 4048]----+
|                 |
|             .   |
|          . ...  |
|         o  +E++.|
|        S o +=o+=|
|       . o.*.Xo.=|
|        + +*B++=o|
|       . . oO..+B|
|           o. .+O|
+----[SHA256]-----+

After key generation copy the key towards your remote client here I have one client with IP “192.168.7.219”

linuxhelp1:/etc/sysconfig/network # ssh-copy-id root@192.168.7.219
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.7.219 (192.168.7.219)' can't be established.
ECDSA key fingerprint is SHA256:o3IxdP2+ivCQvJcaD4dw9VItzSSD/upuNn6PGVqZwGU.
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
root@192.168.7.219's password: 

Number of key(s) added: 1

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

After which take ssh and verify that key has added properly or not

linuxhelp1:~ # ssh root@192.168.7.219
Last login: Fri Aug 24 13:56:54 2018

Create Inventory File for Remote Hosts

Inventory file contains the information about the host to get connected from local to remote. The inventory file will be under /etc/ansible/hosts. We need to add these hosts into the inventory file under webservers group.

linuxhelp1:~ # vim /etc/ansible/hosts
[webservers]
192.168.7.219

Now verify our client server by performing a ping from the here using the ‘ansible‘ command with ‘-m‘(module) option.

linuxhelp1:~ # ansible webservers -m ping
192.168.7.219 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

Next execute commands here for remote machine via following step

linuxhelp1:~ # ansible webservers -a "yum install httpd -y"
 [WARNING]: Consider using the yum module rather than running yum.  If you need to use command because yum is insufficient you can add warn=False to this command task or set
command_warnings=False in ansible.cfg to get rid of this message.

192.168.7.219 | SUCCESS | rc=0 >>
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.fibergrid.in
 * extras: mirrors.fibergrid.in
 * updates: mirrors.fibergrid.in
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-80.el7.centos.1 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-80.el7.centos.1 for package: httpd-2.4.6-80.el7.centos.1.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-80.el7.centos.1.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-80.el7.centos.1.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-80.el7.centos.1.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7_4.1 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
.
.
.
.
  Verifying  : mailcap-2.1.41-2.el7.noarch                                  1/5 
  Verifying  : httpd-tools-2.4.6-80.el7.centos.1.x86_64                     2/5 
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                  3/5 
  Verifying  : apr-1.4.8-3.el7_4.1.x86_64                                   4/5 
  Verifying  : httpd-2.4.6-80.el7.centos.1.x86_64                           5/5 

Installed:
  httpd.x86_64 0:2.4.6-80.el7.centos.1                                          

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7_4.1                  apr-util.x86_64 0:1.5.2-6.el7   
  httpd-tools.x86_64 0:2.4.6-80.el7.centos.1    mailcap.noarch 0:2.1.41-2.el7   

Complete!

Next check the status of it via ansible

linuxhelp1:~ # ansible webservers -a "systemctl start httpd"
192.168.7.219 | SUCCESS | rc=0 >>

To check partition on all remote nodes under webserver group

linuxhelp1:~ # ansible webservers -a "df -h"
192.168.7.219 | SUCCESS | rc=0 >>
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        18G  5.4G   13G  31% /
devtmpfs        897M     0  897M   0% /dev
tmpfs           912M     0  912M   0% /dev/shm
tmpfs           912M  9.1M  903M   1% /run
tmpfs           912M     0  912M   0% /sys/fs/cgroup
/dev/sda1       497M  203M  295M  41% /boot
tmpfs           183M   24K  183M   1% /run/user/0

To check the memory usage on all remote nodes under webserver group

linuxhelp1:~ # ansible webservers -a free
192.168.7.219 | SUCCESS | rc=0 >>
              total        used        free      shared  buff/cache   available
Mem:        1865932     1424336       96216        3428      345380      226036
Swap:       2097148      671364     1425784

With this, the method to install Ansible on OpenSUSE leap 15.0 comes to an end.

FAQ
Q
What does the connection plugin represents on Ansible?
A
the connection plugin on ansible represents

term:Connection Plugins to define types of available transports. These are simply how Ansible will reach out to managed systems. Transports included are paramiko, ssh (using OpenSSH), and local.
Q
what is Lookup Plugin in Ansible?
A
A lookup plugin in ansible is a way to get data into Ansible from the outside world. Lookup plugins are an extension of Jinja2 and can be accessed in templates, e.g., {{ lookup('file','/path/to/file') }}. These are how such things as with_items are implemented.
Q
How do I disable cowsay on Ansible?
A
To disable cosway on ansible You can either uninstall cowsay, or set the ANSIBLE_NOCOWS environment variable:

export ANSIBLE_NOCOWS=1
Q
Where does the configuration file exist and what can I configure in Ansible?
A
To Find the Existing configuration File and ansible configuration

Please refer their official documentation : "https://docs.ansible.com/ansible/2.5/installation_guide/intro_configuration.html"
Q
What is the best way to make content reusable/redistributable in Ansible?
A
The best way to make content reusable/redistributable in Ansible is

See about “Roles” with which you can make playbook content self-contained, and it works well with things like git submodules for sharing content with others