Ansible - dynamically include Jinja templates and tasks

For my ansible playbooks, I wanted to be able to add several new templates to be copied to target system, and additionally be able to perform some commands for them without having to specify each individual file/template to copy. My approach: Define for the hosts I want to find templates/playbooks define a var named extras for the relevant hosts: extras: - ntp - certificates The names defined (in above example ntp and certificates) are just name of folders laying inside tasks/templates/${folder} that are searched and included or excluded based on extras values....

September 24, 2022 · 2 min · Pablo Iranzo Gómez

Include Ansible playbooks sorted

Use sorted list for included files vs random provided by with_fileglob. - name: Include tasks include_tasks: "{{item}}" loop: "{{ query('fileglob', 'tasks/*.yaml') | sort }}"

September 23, 2022 · 1 min · Pablo Iranzo Gómez

Ansible setup for VPN using WireGuard

Setting up WireGuard is not a difficult process but I wanted to automate it among hosts by using a simple playbook that can be executed against the hosts and get it configured and deployed in a simple way. I also wanted to require the minimum possible number of values in the inventory, so tried to automate lot of the information required, leaving in the end only some required values: wireguard: True wgrole: 'master' or 'something else' wgport: port number to use The first step was to create the private and public key once the wireguard package is installed....

March 17, 2022 · 5 min · Pablo Iranzo Gómez

How to check if a system is virtual

I was improving a playbook in Ansible and wanted to find a way to find if a system was virtual or not to decide about some tunning like setting tuned-adm profile virtual-guest or disable the power off when the lid is closed. After some research and try-except situations I got to this one that seemed to work (I had to tune it as one desktop machine was missing the /sys entry I was using before):...

May 10, 2021 · 3 min · Pablo Iranzo Gómez

InfraRed for deploying OpenStack

InfraRed is tool that allows to install/provision OpenStack. You can find the documentation for the project at http://infrared.readthedocs.io. Also, developers and users are online in FreeNode at #infrared channel. Why InfraRed? Deploying OSP with OSP-d (TripleO) requires several setup steps for preparation, deployment, etc. InfraRed simplifies them by automating with ansible most of those steps and configuration. It allows to deploy several OSP versions Allows to ease connection to installed vm roles (Ceph, Computes, Controllers, Undercloud) Allows to define working environments so one InfraRed-running host can be used to manage different environments and much more… Setup of InfraRed-running host Setting InfraRed is quite easy, at the moment the version 2 (branch on github) is working pretty well....

February 23, 2017 · 4 min · Pablo Iranzo Gómez
This blog is a participant in the Amazon Associate Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.