It was asked to have the playbooks shared with the community from the Ansible demo that was presented at the Red Hat Summit. Down below, I have each of the playbooks posted for anyone to take a look at and review. Please note that since this was my first time messing around with Ansible, there are most likely cleaner ways to do some of these activities, but these worked for our demo and should be a good starting point for others that want to try it out. Each playbook was broken into sections, but there’s no reason that you could not put all of these into a single playbook. With that said, here you go!
Playbook #1 – Basic Provisioning of EC2 instances in AWS.
---
# Basic provisioning of EC2 instances.
- name: Create AWS resources
hosts: localhost
connection: local
gather_facts: False
tasks:
- name: Create an EC2 instance
ec2:
aws_access_key: "{{aws_access_key}}"
aws_secret_key: "{{aws_secret_key}}"
key_name: "{{key_name}}"
region: "{{aws_region}}"
group_id: "{{firewall_group_id}}"
instance_type: "{{instance_type}}"
vpc_subnet_id: "{{vpc_subnet_id}}"
image: "{{ami_id}}"
assign_public_ip: yes
wait: yes
volumes:
- device_name: /dev/sda1
volume_type: gp2
volume_size: 10
delete_on_termination: true
exact_count: 5
count_tag:
Env: Demo
instance_tags:
Name: ansible-aws-rhs
Project: RHS-Demo
Env: Demo
register: ec2
Playbook #2 – Install Apache on EC2 instances using a dynamic inventory.
---
- name: This sets up an httpd webserver
hosts: tag_Env_Demo
become: yes
tasks:
- name: Install the httpd rpm
yum: name=httpd
- name: start the httpd service
service: name=httpd state=started
Playbook #3 – Get ONTAP version information from Cloud ONTAP. In this playbook, you need to define your host as the NetApp EC2 instance IP address.
---
- hosts: netapp
gather_facts: no
tasks:
- name: Get ONTAP Version
raw: version
register: ontap_version
- debug: var=ontap_version
Playbook #4 – Clone the Demo volume that we used in our demo. Change the command for your particular volume name and snapshot parent name and date. (Please note that the raw command is one line but is wrapping in this display)
---
- hosts: netapp
gather_facts: no
tasks:
- name: Create Demo Clone FlexClone from SnapMirror
raw: volume clone create -vserver svm_RHSAnsible -flexclone DemoClone -type RW -parent-vserver svm_RHSAnsible -parent-volume RHSAnsible_copy -parent-snapshot daily.2018-05-19_0010 -junction-path /DemoClone -junction-active true
register: output
- debug: var=output
- name: Create Export Policy
raw: volume modify -vserver svm_RHSAnsible -volume DemoClone -policy export-svm_RHSAnsible-RHSNFS
register: output2
- debug: var=output2
Playbook #5 – Installs NFS client tools and mounts the DemoClone volume that we created. Also sets the appropriate access.
---
- hosts: tag_Env_Demo
become: yes
gather_facts: yes
vars:
aws_profile: default
aws_region: us-east-1
nfs_package: nfs-utils
rhs_mount_dir: /rhs
tasks:
- name: Ensure NFS is installed.
package: "name={{ nfs_package }} state=installed"
- name: Ensure mount directory exists.
file:
path: "{{ rhs_mount_dir }}"
state: directory
mode: 0777
- name: Mount NFS volume
mount:
path: /rhs
src: '10.0.1.117:/DemoClone'
fstype: nfs
state: mounted
Playbook #6 – Copies a modified httpd.conf file from our DemoClone volume and overwrites the existing one. There is definitely a better way to do this change but we needed something quick.
---
- name: Import apache directory configuration
hosts: tag_Env_Demo
become: yes
tasks:
- name: Copy httpd.conf file
copy:
src: /rhs/httpd.conf
dest: /etc/httpd/conf/httpd.conf
owner: root
group: root
mode: 0644
remote_src: yes
- name: Change Apache NFS permissions
command: setsebool -P httpd_use_nfs 1
- name: start the httpd service
service: name=httpd state=restarted
That’s it! I hope that helps folks. I’m going to be updating playbooks 3 and 4 soon to work with the new NetApp modules. Hopefully next week.
Last note. I hope the font for the code is acceptable. It’s not so straightforward to post code in WordPress. Another thing to learn!
Matt