Getting started with ansible on fedora 26

Once we have installed ansible, it can be tested with localhost without much of additional configuration.

Lets setup a passwords login for user cipher on localhost which i will be using to test.

$ssh-copy-id cipher@localhost 
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/cipher/.ssh/id_rsa.pub"
/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
cipher@localhost's password: 

Number of key(s) added: 1

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

Now user cipher can access cipher@localhost without any password, lets fire up a simple ansible command to test.

$ansible all -i localhost, -m ping 
localhost | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

results says we are able to connect to the server over ssh.

The above example was to test on a localhost without much configuration, when we want to manage large number of hosts they can be added in ansible inventory file located at /etc/ansible/hosts

here is a default ansible configuration file on fedora 26.

$cat /etc/ansible/hosts
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
#   - Blank lines are ignored
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses
#   - A hostname/ip can be a member of multiple groups

# Ex 1: Ungrouped hosts, specify before any group headers.

## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10

# Ex 2: A collection of hosts belonging to the 'webservers' group

## [webservers]
## alpha.example.org
## beta.example.org
## 192.168.1.100
## 192.168.1.110

# If you have multiple hosts following a pattern you can specify
# them like this:

## www[001:006].example.com

# Ex 3: A collection of database servers in the 'dbservers' group

## [dbservers]
## 
## db01.intranet.mydomain.net
## db02.intranet.mydomain.net
## 10.25.1.56
## 10.25.1.57

# Here's another example of host ranges, this time there are no
# leading 0s:

## db-[99:101]-node.example.com

Inventory file can be in INI deafult ansible syntax or it can be in json format.
mail.example.com

[webservers]
one.ansible.box
two.ansible.box

[dbservers]
three.ansible.box
four.ansible.box

Lets spin up 2 vms called linux3 and linux4 that can be used with ansible.

$sudo virsh vol-create-as  store linux3 25G
Vol linux3 created

$ sudo virsh vol-create-as  store linux4 25G
Vol linux4 created

Centos 7 can be installed to these new volumes with virt-install command.

Setting up new vms is a time consuming process we can use virt-clone to clone the existing vm then sysprepping it to remove old configuration settings.

$virt-clone --force -o linux3 -n linux4 -f /dev/store/linux4
WARNING  This will overwrite the existing path '/dev/store/linux4'
WARNING  The filesystem will not have enough free space to fully allocate the sparse file when the guest is running. 25600 M requested > 1955 M available
Cloning linux3                                                                                                                                                                                       |  25 GB  00:13:44     

Clone 'linux4' created successfully.

resetting the newly created vm.

$virt-sysprep -d linux4 
[   0.0] Examining the guest ...
[  36.6] Performing "abrt-data" ...
[  36.6] Performing "backup-files" ...
[  43.8] Performing "bash-history" ...
[  43.8] Performing "blkid-tab" ...
[  43.8] Performing "crash-data" ...
[  43.8] Performing "cron-spool" ...
[  43.9] Performing "dhcp-client-state" ...
[  43.9] Performing "dhcp-server-state" ...
[  43.9] Performing "dovecot-data" ...
[  43.9] Performing "logfiles" ...
[  44.5] Performing "machine-id" ...
[  44.5] Performing "mail-spool" ...
[  44.5] Performing "net-hostname" ...
[  44.5] Performing "net-hwaddr" ...
[  44.5] Performing "pacct-log" ...
[  44.5] Performing "package-manager-cache" ...
[  44.6] Performing "pam-data" ...
[  44.6] Performing "passwd-backups" ...
[  44.6] Performing "puppet-data-log" ...
[  44.6] Performing "rh-subscription-manager" ...
[  44.6] Performing "rhn-systemid" ...
[  44.6] Performing "rpm-db" ...
[  44.6] Performing "samba-db-log" ...
[  44.6] Performing "script" ...
[  44.6] Performing "smolt-uuid" ...
[  44.6] Performing "ssh-hostkeys" ...
[  44.6] Performing "ssh-userdir" ...
[  44.6] Performing "sssd-db-log" ...
[  44.6] Performing "tmp-files" ...
[  44.7] Performing "udev-persistent-net" ...
[  44.7] Performing "utmp" ...
[  44.7] Performing "yum-uuid" ...
[  44.7] Performing "customize" ...
[  44.7] Setting a random seed
[  44.7] Setting the machine ID in /etc/machine-id
[  45.7] Performing "lvm-uuids" ...

Checking for the new vms created.

$ virsh list 
 Id    Name                           State
----------------------------------------------------
 2     linux3                         running
 4     linux4                         running