-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to rename host inventory variables using patterns #4
Conversation
Certain environments may have conflicts with the variables given by Netbox, and the variables used in the existing Ansible codebase. With this change, such cases can be worked around by renaming individual variables, or whole groups of them. For example, this will rename all `cluster*` variables to have a `netbox__` prefix instead (e.g., `cluster_group` -> `netbox__cluster_group`): ```yaml rename_variables: - pattern: 'cluster(.*)' repl: 'netbox__cluster\1' ``` Uses a list, instead of a dict, to ensure that the order of evaluation is strictly defined across all Python versions, and to add the ability to exclude certain variables from being rewritten. For example: ```yaml rename_variables: # Keep cluster_type the same - pattern: 'cluster_type' repl: 'cluster_type' # Rename all other cluster* variables - pattern: 'cluster(.*)' repl: 'netbox__cluster\1' ```
Tests: 1
LGTM. 2
LGTM. 3
LGTM. 4
LGTM. 5
🛑 Variable 6
LGTM. 7
LGTM. 8
LGTM 9
LGTM. 10
LGTM (expected not to be renamed). 11
🛑 Overwrites all cluster* variables so only the last one is left and named netbox__cluster. 12
LGTM (does not do anything). 13
LGTM. 14
LGTM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
My tests and findings are listed in #4 (comment). Nr. 5 is more of a feature than a bug. Nr. 11 is a known issue, since it would be very tricky to provide an error message in this case, so it's a known issue.
Related Issue
None.
New Behavior
Certain environments may have conflicts with the variables given by Netbox, and the variables used in the existing Ansible codebase.
With this change, such cases can be worked around by renaming individual variables, or whole groups of them.
For example, this will rename all
cluster*
variables to have anetbox__
prefix instead (e.g.,cluster_group
->netbox__cluster_group
):Uses a list, instaed of a dict, to ensure that the order of evaluation is strictly defined across all Python versions, and to add the ability to exclude certain variables from being rewritten. For example:
Contrast to Current Behavior
Currently, variables are hard-coded and there's no way to resolve conflicts with what Netbox wants to set, and the code base that wants to pull inventory variables.
...
Discussion: Benefits and Drawbacks
This change is backward compatible and useful for people that need to integrate existing systems together, where it may not be feasible to give a generic variable like
cluster
a new meaning.Proposed Release Note Entry
Add ability to rename host inventory variables using patterns.
...
Double Check
devel
branch.