2. Allan Denot
∙ 2 year experience with Ansible
∙ 3 years experience with AWS
∙ Senior DevOps Engineer at Odecee
∙ Co-founder of spikenode.com
@denot allandenot.com
14. tasks:
- block:
- name: Shell script to connect the app to a monitoring service.
script: monitoring-connect.sh
rescue:
- name: This will only run in case of an error in the block.
debug: msg="There was an error in the block."
always:
- name: This will always run, no matter what.
debug: msg="This always executes."
Blocks for Error Handling
2.0:
16. Modules
Notorious additions
package - generic OS package manager
- name: install the latest version of ntpdate
package: name=ntpdate state=latest
# This uses a variable as this changes per distro.
- name: remove the apache package
package : name={{apache}} state=absent
expect - executes a command and responds to prompt
- expect:
command: passwd username
responses:
(?i)password: "MySekretPa$$word
find - return a list of files based on criteria
# Recursively find /tmp files older than 4 weeks and equal or greater than 1 megabyte
- find: paths="/tmp" age="4w" size="1m" recurse=yes
# Recursively find /var/tmp files with last access time greater than 3600 seconds
- find: paths="/var/tmp" age="3600" age_stamp=atime recurse=yes
# find /var/log files equal or greater than 10 megabytes ending with .log or .log.gz
- find: paths="/var/tmp" patterns="*.log","*.log.gz" size="10m"
23. Using 2.0 modules TODAY
5 Save under: library/cloud/amazon/iam2.py
6 Use it normally: tasks:
- name: Create two new IAM users with API keys
iam2:
iam_type: user
name: "{{ item }}"
state: present
password: "{{ temp_pass }}"
access_key_state: create
with_items:
- jcleese
- mpython