Ansible testing

14
Testing Ansible with Ansible

Transcript of Ansible testing

Page 1: Ansible testing

Testing Ansible with Ansible

Page 2: Ansible testing

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

Page 3: Ansible testing

Allan Denot @denot allandenot.com

∙ Brazilian

∙ 4 years in Australia

Page 4: Ansible testing

Why we need testing?

Page 5: Ansible testing

TE

AM

BT

EA

M A

The ProblemConfiguring

servers!

Deploying

app!

Page 6: Ansible testing

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?

Page 7: Ansible testing

SolutionConfiguring

servers!

Ok, let me

check.

TE

AM

BT

EA

M A

All good!

Deploying app!

Page 8: Ansible testing

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

Page 9: Ansible testing

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

Page 10: Ansible testing

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

Page 11: Ansible testing

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"

Page 12: Ansible testing

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

Page 13: Ansible testing

Demo

Page 14: Ansible testing

Questions?

Links

github.com/adenot/ansible-testing

allandenot.com

spikenode.com