ansible: Quickly create new role structure

Update: Instead of this, just use ansible-galaxy init demo.role

This is based on the Ansible documentation for creating roles.

Create your role name

mkdir demo.role && cd demo.role

Create all the folders we need

mkdir tasks handlers templates files vars meta

Create our empty main.yml files

echo "---" > {handlers,meta,tasks,vars}/main.yml

Alternatively, save the following as /usr/local/bin/ansible-gen-role, chmod +x /usr/local/bin/ansible-gen-role and then use ansible-gen-role role.name (it depends on a zsh feature for multiple redirects)

#!/usr/bin/zsh

mkdir $1 && cd $1
mkdir tasks handlers templates files vars meta
echo "---" > {handlers,meta,tasks,vars}/main.yml
cd ..

2 thoughts on “ansible: Quickly create new role structure

Leave a Reply