0

Sometimes, when I browse an Ansible role, I see that a developer has put double underscores for a variable.

As Ansible is based on Python, I assumed it was a Pythonic thingy.

When I read the docs of Ansible, it states:

In many programming languages, variables that begin with an underscore are private. This is not true in Ansible. Variables that begin with an underscore are treated exactly the same as any other variable. Do not rely on this convention for privacy or security.

But, as I look at the variables, I'm actually not sure why this is done.

Q: Can someone explain to me in detail what the reason is to apply double underscores for varaibles in Ansible?

Kevin C
  • 4,851
  • 8
  • 30
  • 64
  • 3
    It would appear to just be a convention the author of the `sap-preconfigure` role chose to use. *Ansible* doesn't treat them differently, but someone using this role is expected not to change their values; they are set in various OS-specific var files. – chepner Sep 01 '21 at 14:05
  • It is just a coding style and probably based on naming convention. You may have a look into the [use of underscore in variable and method names](https://stackoverflow.com/questions/16785175/). – U880D Nov 17 '21 at 06:52

0 Answers0