Skip to content

Instantly share code, notes, and snippets.

@weshouman
Last active August 19, 2021 15:22
Show Gist options
  • Save weshouman/753137c5ef5852e9a1b19a3898aa1b9f to your computer and use it in GitHub Desktop.
Save weshouman/753137c5ef5852e9a1b19a3898aa1b9f to your computer and use it in GitHub Desktop.
Advanced Ansible hints

Naming

  • Use underscores
  • Do not use hyphens, based on the issues 1042 and 1123

History

  • Previously people used ansible-role-ROLE-NAME and Galaxy removed the ansible-role- part and kept ROLE-NAME
  • Later on galaxy stopped removing the prefix, and left the role maintainers do the heavy-lefting of setting the ROLE-NAME into meta/main.yml:role_name:
    However, there's a trick here, hyphens will be replaced with underscores, only the old roles could keep their hyphens x)
  • Then meta/main.yml:role_name: got deprecated, people got pretty angry as they are now stuck with ansible-role-ROLE-NAME naming, then over time they undeprecated the option

Final takes

  • Use underscores
  • Name the github repo to the role name of desire without prefixes
  • Don't use meta/main.yml:role_name: to avoid any magic in the background
  • Hope there won't be no more surprises :_:

Local Run

To run on the ansible host set the host: 127.0.0.1 & connection: local as depicted in this SOA

Casual Run

To run a role on-spot from the terminal directly, fetch the role locally then run

ansible localhost -m include_role -a name=weshouman.vim_env
# Or with sudo privilege
ansible localhost -m include_role -a name=weshouman.vim_env --become

Getting Modular

Imports are static and Includes are modular, for more on the differences refer to this SOA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment