Testing with Ansible

IEEE Spectrum has recently posted an article about Yahoo resigning from the QA team. After that maneuver quality of the final product not only didn’t degrade but actually improved. Of course, if we delve deeper into the article we will realize that the products got better after continuous delivery introduction (image credit towww.cloudofit.com) and the QA team wasn’t entirely to blame. However, that’s a clear signal to old school testers that programming/scripting skills are now necessary.

One of my favorite tools that support Continuous Delivery (or Deployment if we assume what deploy to production is automatic) is Ansible. This simple automation agent allows us to execute commands on external hosts via plays, which can later be organized to playbooks (list of plays). This is how example playbook looks like:

- hosts: droplets
    - name: Installs nginx web server
      apt: name=nginx force=yes update_cache=true

    - name: start nginx
      service: name=nginx state=started

What is this playbook doing?

a) it checks hosts file for [droplets] string and connects to IP addresses below. Hosts file example:


b) apt-get update is called (update_cache=true)

c) apt-get install nginx is called with automatic confirmation (name=nginx force=yes)

d) nginx service is started

With very few lines we were able to install the necessary applications on two hosts. Imagine how much time you’ll save if the number of machines would be bigger. Probably you have already realized how powerful Ansible can it be to testing, but let me give you a few more examples:

  • Environment setup (see example above)
  • Updating app configuration on all testing servers
- hosts: test_machines
    - name: Update config
      template: src=config.xml.j2 dest=/config.xml
  • Jenkins / Selenium Grid / Selenium nodes auto-configuration
  • Smoke tests after prod deployment
- hosts: PROD_machines
    - name: Check service
      service: name=vsftpd state=started
  • Running commands and checking the output
- hosts: test_machines
    - name: Run X
      shell: usr/bin/somefancycommand
      register: cmd_result

    - name: assert results
      that: "not ready not in cmd_result.stderr"

Free knowledge:

Tags: , , , , , ,