I want to show you some tricks and solutions that I designed along my journey automating stuff with Ansible. To use these tricks doesn't matter if you are new in the Ansible world or already are a power user.
How to learn Ansible?
If you want to learn a lot of stuff from a really competent person, Jeff Geerling has an awesome playlist on his YouTube channel. The geerlingguy (his GitHub/Twitter name account) was part of the Ansible team and still maintaining many Ansible roles and collections. This is the best source that I can recommend for any beginner and even more advanced users today (2021).
Free Ansible Workshops available on GitHub:
Instruqt - Self-paced and interactive lab training:
Free Red Hat introduction to Ansible and Automation Controller (AWX):
A good reference to an article from my work college John Westcott:
Basics
Common structures
Install binary from remote
A common problem that I face is installing the latest version of an application from a GitHub release, so here are two examples of how to do that.
Install binary from GitHub release:
Extract specific files from remote:
Conditionals
How to create more complex and host specific checks.
Content in file
Ansible offers two major ways to ensure that a text content is present in a file.
Error handling
Check for installed package
Sometimes you may want to check if a package is installed and raise a proper error, without actually installing something or needing root access.
I am a senior software engineer at Red Hat / Ansible. I love automation tools, games, and coffee. I am also an active contributor to open-source projects on GitHub.