Trishna Guha (@trishnag)
Associate Software Engineer
Ansible by Red Hat
---
- name: main playbook
hosts: localhost
become: yes
become_method: sudo
tasks:
- name: install httpd
dnf:
name: httpd
state: latest
---
- name: main playbook
hosts: localhost
become: yes
become_method: sudo
tasks:
- name: install httpd
dnf:
name: httpd
state: latest
- debug:
msg: "{{ result }}"
- ping:
[atomic]
192.168.1.1 ansible_ssh_private_key_file=<SSH_KEY_FIILE>
[nxos]
172.24.4.16 ansible_connection=local ansible_user=user ansible_ssh_pass=pass
[targets]
localhost ansible_connection=local
other1.example.com ansible_connection=ssh ansible_user=mpdehaan
other2.example.com ansible_connection=ssh ansible_user=mdehaan
Collection of tasks, playbooks
Run multiple times
One very large playbooks ?
Organize and Manage Files in maintainable manner
# vars/guests.yml
---
domain: atomic-node
image: Fedora-Atomic-25-20170215.1.x86_64
cpu: 1
mem: 1536
os:
variant: fedora23
path: /tmp
Continued
---
# This playbook creates VM from the QCOW2 Image
- include_vars:
file: vars/guests.yml
- name: Copy qcow2 image to the instance qcow2
copy:
src: '{{ path }}/{{ image }}.qcow2'
dest: /var/lib/libvirt/images/{{ domain }}.qcow2
- name: Create VM from QCOW2
shell: virt-install --quiet --import --name={{ domain }}
--os-variant={{ os.variant }} --ram={{ mem }} --vcpus={{ cpu }}
--disk path=/var/lib/libvirt/images/{{ domain }}.qcow2,format=qcow2,bus=virtio
--disk path=/var/lib/libvirt/images/{{ domain }}.cidata.iso,device=cdrom,readonly=on
--network network=default --noautoconsole
- name: Make sure that the VM is running
virt: name={{ domain }} command=start
ignore_errors: yes
---
# Main Entrypoint
- name: Main Playbook
hosts: localhost
become: yes
become_method: sudo
tasks:
- include: create-vm.yml
- include: compose.yml
---
# This playbook installs requirements
- name: Install the list of required packages
package: name={{ item }} state=installed
with_items:
- genisoimage
- libvirt
- libselinux-python
- qemu-img
- rpm-ostree
- ostree
- virt-install
- name: Download daemon rpm and Install
command: "{{ item }}"
with_items:
- wget -P /tmp http://libslack.org/daemon/download/daemon-0.6.4-1.x86_64.rpm
- rpm --install /tmp/daemon-0.6.4-1.x86_64.rpm
ignore_errors: yes
- name: Create directory structure
file: path={{ item }} state=directory mode=750
with_items:
- "/srv/repo"
- "/srv/cache"
- "{{ abs_path }}"