Ansible testing
-
Upload
allan-denot-medeiros -
Category
Software
-
view
179 -
download
0
Transcript of Ansible testing
Testing Ansible with Ansible
Allan Denot
∙ 1 year experience with Ansible
∙ 2 years experience with AWS
∙ DevOps Engineer at cammy.com (previously Suncorp)
∙ Co-founder of spikenode.com
@denot allandenot.com
Allan Denot @denot allandenot.com
∙ Brazilian
∙ 4 years in Australia
Why we need testing?
TE
AM
BT
EA
M A
The ProblemConfiguring
servers!
Deploying
app!
The ProblemT
EA
M B
App is not working. Was
the server configured?
TE
AM
A
Yes... Probably...
Oh wait, our
playbook failed
Then why apache is
not installed?
SolutionConfiguring
servers!
Ok, let me
check.
TE
AM
BT
EA
M A
All good!
Deploying app!
server
SolutionT
EA
M B asserts the state of the servers before deploying and
only deploys if passes
Useful when different teams are in charged of different layers of configuration.
operational system
web server
database
application
Testing with custom moduleExample playbook:
- name: Test Setup Webservers hosts: all tasks:
- assert_file: name=/apps should_be=directory - assert_owner: name=/apps should_be=appuser
- assert_tcp: name=localhost:80 should_be=open with_timeout=3
Custom module
https://github.com/adenot/ansible-testing
Testing permissions:
- assert_mode: name=/tmp/testfile should_be=0755
- assert_owner: name=/tmp/testfile should_be=adenot
- assert_group: name=/tmp/testfile should_be=users
Custom module
https://github.com/adenot/ansible-testing
Testing files/directories:
- assert_group: name=/tmp/testfile should_be=users
- assert_file: name=/tmp/testfile should_be=file
- assert_file: name=/tmp/testdir should_be=directory
- assert_content: name=/tmp/testfile should_match="example.*string"
Custom module
https://github.com/adenot/ansible-testing
Testing processes/ports:
- assert_process: name=/sbin/agetty should_be=running with_args='38400'
- assert_tcp: name=localhost:9001 should_be=open with_timeout=3
- assert_command: name='netstat -nl|grep ":9001"' should_be=successful
Demo
Questions?
Links
github.com/adenot/ansible-testing
allandenot.com
spikenode.com