Sat, March 31, 2018 ยท 1 min read

Getting started with ansible on fedora 26

Getting started with ansible on fedora 26

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

Setup passwordless SSH

$ ssh-copy-id cipher@localhost
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/cipher/.ssh/id_rsa.pub"
Number of key(s) added: 1

Test Ansible with ping

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

Ansible inventory file

The default inventory file is at /etc/ansible/hosts. Example:

mail.example.com

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

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

Cloning VMs for Ansible testing

Create new volumes and use virt-clone to clone existing VMs:

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

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

$ virt-clone --force -o linux3 -n linux4 -f /dev/store/linux4
Clone 'linux4' created successfully.

Reset the cloned VM with virt-sysprep

$ virt-sysprep -d linux4
[   0.0] Examining the guest ...
[  36.6] Performing "abrt-data" ...
...
[  45.7] Performing "lvm-uuids" ...

Check VMs

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