Simple Ansible Makefile

I love using Ansible for deploying projects these days, but I don’t like typing the same long command over and over. It’s usually something like this:

ansible-playbook -i hosts --vault-password-file=.vault-password.txt site.yml

It’s simple to create a Makefile to automate this, but I wanted to go one further. For speed purposes, I like to run particular roles separately sometimes.

My new Makefile:

tags = $(subst roles/,,$(wildcard roles/*))
.PHONY: all $(tags)

all:
	ansible-playbook -i hosts --vault-password-file=.vault-password.txt site.yml

$(tags):
	ansible-playbook -i hosts -t $@ --vault-password-file=.vault-password.txt site.yml

Now I can run, for example, make nginx to just run the Nginx role. You can see this in action at my homebase repository.