ansible for application smoketests March 22, 2014
Likely most are using Ansible for provisioning of new system to include: spinning up instances, deploying applications and applying configurations. While this is the typical use case Ansible may be leveraged to provide much more. One such extension of its use is with application smoketests.
By knowing what an end, state should look like we can create various tests to verify this functionality. Through smoketests, you are able to gain better insight into the state of deployed systems and their applications.
Smoketests can also be leveraged at various places in your pipeline.
- Hooking into your continuous integration environment to test the state of playbooks
- Post deployed verification of new systems
- Use for troubleshooting by operations.
For example, we may take an install of elasticsearch. We know a couple things after install such as the service running and certain ports listening.
- name: status action: command service elasticsearch status register: status failed_when: "status.stdout.find('stop/waiting') != -1" changed_when: False - name: check cluster status action: command curl -X GET 'http://localhost:9200/_cluster/health' register: result failed_when: not result.stdout.find('"status":"green"') changed_when: False - name: ports action: "command lsof -iTCP:9200,9300 -sTCP:LISTEN -Pn" register: ports failed_when: "ports.stdout_lines|count < 2" changed_when: False
The previous will ensure the service is running, the cluster is green and the ports are listening properly and error out if any one of those checks fails.
I hope that this gives you some ideas of how to implement this in your own environment. I would love to hear ideas of how others are using something such as somketests to discern system and application state.
Questions/Comments/Praises can be sent to me at firstname.lastname@example.org