Manage Apache VirtualHosts and mod_rewrite Rules with Ansible

Published June 2, 2014


I needed a way to manage Apache VirtualHosts and mod_rewrite rules. There are a handful of Ansible Roles available at Ansible Galaxy to manage Apache VirtualHosts, but none of them also manage mod_rewrite rules.

After figuring out how to include additional content in an Ansible Template file, I was able to quickly put together an Ansible Playbook and Ansible Template to manage my Apache VirtualHosts and their particular mod_rewrite rules.

Continue reading...

Include Additional Content in Ansible Template File

Published May 22, 2014 • Updated May 27, 2014


While putting together an Ansible Playbook to generate a configuration file from an Ansible Template, I needed a way to include additional content from a text file within the generated configuration file. I could not find an Ansible Module to do this, but Ansible uses the Jinja2 templating engine, and with one additional line in the Ansible Template file, I was able to include the contents of the text file in the generated configuration file.

Continue reading...

Ansible Manage the Same Users Across Servers with Different Passwords

Published April 19, 2014 • Updated February 16, 2019


Recently, I was setting up a handful of servers that all needed the same user created but with a different password for that user on each server. After Google searching, I did not find a definitive way to manage users, and most of what I found consisted of bits and pieces of what I was looking for. I ultimately settled on the following solution.

This solution can definitely be improved upon by using group_vars and variable overrides to remove redundant attributes.

Continue reading...

Install Ansible, Create an Inventory File, Create and Run an Ansible Playbook, and Run Ansible Commands

Published March 8, 2014 • Updated June 28, 2018


Ansible is part of the configuration management and orchestration family that includes Puppet, Chef, and SaltStack. Having only ever used Chef, I found Ansible to have a much lower learning curve. I spent more time using it rather than learning it. But, despite its ease of use, there is always some amount of pre-work needed to get started.

In this post I will be stepping through how to install Ansible, create and run your first Ansible Playbook, and how Ansible can be used to run ad hoc commands. I will be running everything from OS X Mavericks. With the possible exception of the installation, all the other steps should work on modern Linux distributions.

Continue reading...