ansible-make-role
Pre-compiler that turns a single-file role definition into Ansible role files.
The role.yml file combines the Ansible main.yml where each main.yml file
is represented by a section (defaults:, vars:, tasks: etc.)
Usage
ansible-make-role -c|--clean -f|--force -g|--git -r|--roles=DIR -v|--verbose --version DIR...
ansible-make-role expects a role.yml file in each of the given directories
and generates an Ansible role in it. Existing main.yml files will be
overwritten or removed but other files won't be touched
ansible-make-role only generates up-to-date files unless the --force option
is used
Description
The make.yml contains a section for each generated file so that eg. the
tasks section becomes the tasks/main.yml file. The supported sections are
defaults, vars, tasks, and handlers. Anything outside of those sections
(notably dependencies) goes to the meta/main.yml file
Example:
---
dependencies: # Goes to meta/main.yml
- role: rails-server
defaults: # Goes to defaults/main.yml
appl_name: "myapp"
appl_domain: "mydomain.com"
vars: # Goes to vars/main.yml
appl_host: "{{ appl_name}}.{{ appl_domain }}"
tasks: # Goes to tasks/main.yml
- name: "Ensure Apache"
yum: name=httpd state=present
notify: restart_httpd
- name: "Ensure Apache is enabled"
service: name=httpd enabled=yes
handlers: # Goes to handlers/main.yml"
- name: restart_httpd
servide name=httpd state=restarted
...
Options
-c, --clean
Clean the project by removing autogenerated files
-f, --force
Re-generate all files even if not needed
-g, --git
Also handle per-role .gitignore files. Note that the .gitignore file will be overwritten
-r, --roles=DIR
Use DIR instead of default ./roles
-v, --verbose
Report progress
--version
Print version
Installation
Install it for the current ruby using:
$ gem install ansible_make_role
Please note that the gem name uses underscores but the command uses dashes ('ansible-make-role')