Archive
Posts from 2017
Using ansible's templating capabilities to deliver a keepalived configuration file
I've become a huge fan of ansible's templating capabilities over the past few months. If you haven't used them they allow you to control the content of a file that is delivered to a system. The templates can contain variable names which get filled in with well known values, you can use math operations and various filters to derive values, and these can all be wrapped in logic statements to control when and where this occurs. To illustrate this lets say we are looking to stand up a fault tolerant haproxy cluster and want to use keepalived to control the virtual IPs that float between servers…
$ read more →Getting the ansible yum module to work on Fedora servers
I was doing some testing this morning on a Fedora 25 host and received the following error when I tried to execute a playbook: To see what ansible was doing I set the ANSIBLE_KEEP_REMOTE_FILES environment variable which keeps the ansiballz modules on the remote host (this is super useful for debugging problems). After reviewing the files in the temporary task directory I noticed that the playbook had a task to install a specific version of a package with yum. Yum doesn't exist on newer Fedora releases hence the "python2 yum module" error. There are a couple of ways to fix this…
$ read more →Viewing ansible variables
When developing ansible playbooks and roles it's extremely useful to be able to see all of the variables available to you. This is super easy with the ansible setup and debug modules: List all of the vars available to the host: $ Retrieve all of the groups from the inventory file: $ Lester Wade took this a step further and wrote a great blog entry that describes how to dump the contents of the vars, environment, group_names, hostvars and group variables to a file. If you run his example you will get a nicely formatted text file in /tmp/ansible.all This file is a great reference and kudos to Lester for the amazing work!
$ read more →Conditionally restarting systemd services
In a previous post I discussed how one of my systemd services was getting continuously restarted causing the CPU to spike. This isn't ideal and after re-reading the systemd manual page I came across a couple of useful options to control when and how frequently a systemd service will restart. The first option is RestartSec which controls how long systemd will wait to restart a process after a failure occurs. Systemd also has the RestartForceExitStatus and RestartPreventExitStatus which allow you to define the signals that should or should not cause a restart…
$ read more →Updating a file with ansible if the current file is X days old
I'm a heavy user of the Logstash geoip features which utilize the GeoLite database. To keep up to date with the latest mappings I updated my logstash ansible role to check the current database and retrieve a new one if its older than a certain number of days. This was super easy to do with ansible. To get started I defined a couple of variables in group_vars: These variables define the location to put the geoip database, the URL to the latest database and how how often to update the file…
$ read more →