Archive
Posts in Ansible
Using the Ansible uri module to test web services during playbook execution
Ansible has amazing support for testing services during playbook execution. This is super useful for validating your services are working after a set of changes take place, and when combined with serial you can stop execution if a change negatively impacts one one or more servers in your fleet. Ansible has a number of modules that can be used to test services, including the uri module. The uri module allows Ansible to interact with a web endpoint, and provides numerous options to control its behavior…
$ read more →Controlling the inventory order when running an Ansible playbook
This week I was updating some Ansible application and OS update playbooks. By default, when you run ansible-playbook it will apply your desired configuration to hosts in the order they are listed in the inventory file (or in the order they are returned by a dynamic inventory script). But what if you want to process hosts in a random order? Or by their sorted or reverse sorted names…
$ read more →Using the Ansible async module to perform synthetic health tests during playbook runs
I've become a huge fan of Ansible's async support. This is incredibly useful for performing synthetic health tests on services after a task completes. A common use case is patching a server that hosts one or more applications. You ideally want to gracefully stop your application, update packages, reboot, and then test the application to ensure its healthy…
$ read more →Using the profile module to time Ansible playbook runs
This past weekend I spent some time revamping a few playbooks. One of my playbooks was taking a while to run, and I wanted to see how much actual time was spent in each task. Luckily for me, Ansible has a profiling module to help with this. To enable it, you can add the following directive to the default section in your ansible.cfg configuration file: Future playbook runs will result in a timestamp being printed for each task: And a global summary will be produced once the playbook completes: Super useful feature, especially when you are trying to shave time off complex playbook runs.
$ read more →Which file descriptor (STDOUT, STDERR, etc.) is my application writing to?
When developing ansible playbooks a common pattern is to run a command and use the output in a future task. Here is a simple example: In the first task dnf will run and the output from the command will be placed in either STDOUT or STDERR. But how do you know which one? One way is to add a debug statement to your playbook: Once the task runs you can view the stderr and stdout fields to see which of the two is populated: In the output above we can see that stderr is empty and stdout contains the output from the command…
$ read more →