Package: ansible-roler
ansible-roleransible-roleris a simple command line tool to setup the recommendet folder structure for a new ansible role.Table of ContentSetupUsageConfigurationDefaultsBase configurationTemplatingLicenseMaintainers and ContributorsSetup# From internal pip repo as userpipinstallansible-roler--user# .. or as rootsudopipinstallansible-rolerUsage$ansible-roler--help
usage:ansible-roler[-h][-cCONFIG_FILE][-nNAME][-pPATH][-v]Manageansibleroleenvironments

optionalarguments:-h,--helpshowthishelpmessageandexit-cCONFIG_FILELocationofconfigurationfile:[/Users/rkau2905/Library/ApplicationSupport/ansible-role/config.ini]-nNAME,--nameNAMENameofthenewrole-pPATH,--pathPATHPathwherethenewrolewillbecreated-v,--verboseShowmoreverboseoutputConfigurationDefaultsansible-rolerwill create the the minimal recommended folder structure:common/
    tasks/
        main.yml
    handlers/
        main.yml
    templates/
    files/
    vars/
    defaults/
        main.yml
    meta/
        main.ymlThe main.yml files will be created only if you enable thetemplating feature. Otherwise
the folders will be left empty.Base configurationIn addition to the command line options there are parameters you can adjust in a config file. The default location
for your config file is~/ansible-roler/config.inibut you can place it anywhere and
specifiy the path withansible-roler -c /path/to/config.ini.[base]# base path ansible-roler will use to create new rolesbase_path=~/ansibleroles[logging]# error | warning | info | debug# you can also control this with commandline attribute -vvvlog_level=warningTemplatingIn special cases it can be helpfule to add templated files to each new role. The templating function
can be used to place in customized meta/main.yml or a default config file for your CI in each new role.
The templating is disabled by default and must be enabled in the config file befor you can use it.[templating]# enable template functionalityenable_templating=false# path to your own subdir template file# if not in config file default one will be used# if added empty 'subdir_template=' subdir templating is disabledsubdir_template=/home/jdoe/ansible/custom/main.yaml.j2# if you like you can exclude some subdirs from templating# these folders will be left emptyexclude_subdirs=templates,vars,files# path to your own ci template file# if not in config file default one will be used# if added empty 'ci_template=' ci templating is disabledroot_template=/home/jdoe/ansible/custom/.drone.yaml.j2[template-vars]# define some variables you want to use in your templatemeta_author=John Doemeta_license=MITansible-rolercomes with simple default template file but as you can see in the config you can
customize and use your own. The default file looks as follows:---{%ifsubdir=='tasks'%}# Contains the main list of tasks to be executed by the role.
# Don't add tasks directly to the main.yml use includes instead
- include_tasks: setup.yml{%endif%}{%ifsubdir=='handlers'%}# Contains handlers, which may be used by this role or
# even anywhere outside this role.{%endif%}{%ifsubdir=='defaults'%}# Default variables for the role.{%endif%}{%ifsubdir=='meta'%}galaxy_info:
  author:{{vars.meta.author|default('UNKNOWN')}}description: Deploy some application
  license:{{vars.meta.author|default('MIT')}}min_ansible_version: 2.4
  platforms:
    - name: EL
      versions:
        - 7
  galaxy_tags:
    - myapp
dependencies: []{%endif%}Currently, you can set two template files:subdir_template: template will be deployed to the folders, tasks, handlers, defaults and meta.
This can be used to provide a pre-configured main.yml in each of these folders.root_template: tempate will be deployed to the root of your role.
This can be used to provide a default config for your ci system.Templating inansible-rolerworks only with two static jinja2 files but you can control the content
of the destination file with variables. Following variables will be automatically passed to the template
processor:subdir_templaterolename: these variable holds the rolename you have passed toansible-rolerIf you have prefixed your role with prexix.myrole only the second part will be used.subdir: these variable holds the current subdir which is processed at this time.
This is a good option to add differen content to your destination file in relation to
the current directory. You look at the usage in the build-in example above.root_templaterolenameThere is also an option to set custom variables. These variables will be accessable througvars.
This variable is an empty dictionary as long as you don't set some variables. Therefore you have to
define variables under the `template-vars' section in config file.[template-vars]# define some variables you want to use in your templatemeta_author=John Doemeta_license=MITVariable names will be split at the first underscore. The first part is used as the name
of a sub-dict undervarsthe other part is used as the of your variable. The result of the
these small example looks as follows:{'meta':{'author':'John Doe','license':'MIT'}}If you want to access your variables in a template, here is an example{{ vars.meta.author }}.LicenseThis project is licensed under the MIT License - see theLICENSEfile for details.Maintainers and ContributorsRobert Kaussow