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 ..
Michael is a polyglot software engineer, committed to reducing complexity in systems and making them more predictable. Working with a variety of languages and tools, he shares his technical expertise to audiences all around the world at user groups and conferences. You can follow @mheap on Twitter
Thoughts on this post
Thanks a lot! For me it’s much more easier to use your script!