1

When writing a custom role for an Ansible playbook, it's possible to specify defaults. I would like to do the same when using a role from Ansible Galaxy (the Ansible “package manager”).

For example, when using the popular redis role, I'd like to be able to specify a default redis_version, so that anyone importing that role will get the same.

Without centralizing this, I would put the redis version into the variable section in every playbook when using the role. That's not ideal. Other ways I can think of:

  • Create a new role, put the default variable there, and then make the Galaxy-role a dependency. (Not sure if variables are passed down.)
  • Put the default into ansible.cfg[defaults].

What's the best-practice?

mknecht
  • 111
  • 3

1 Answers1

0

Figure out where to define a variable, and don’t make it complicated. Variable Precedence: Where Should I Put A Variable?

For example, group_vars alongside the playbook. Or from dynamic inventory. Lots more places to put variables too.

If you want the user to only need to import a role, with no variables in their play or inventory, consider forking the role and changing the default. You now have to maintain that, which is a disadvantage. I would rather have my variables in a play, it is just a few lines.

John Mahowald
  • 30,009
  • 1
  • 17
  • 32