-
Notifications
You must be signed in to change notification settings - Fork 290
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 jinja2 template option to inventory plugin for auth_token #1342
Add jinja2 template option to inventory plugin for auth_token #1342
Conversation
Can you elaborate please why now you can't put password or token encrypted by ansible-vault? |
Agreed |
Unless I was doing something completely wrong, any sort of jinja2 templating did not work for the inventory plugin. It works fine for other modules in the collection but didn't seem to work for me with the inventory plugin. I confirmed by doing the connection from ansible to zabbix API over http and sniffing the packets. I could see the jinja2 string for the auth_token was passed unchanged to the API. So it seemed as if to me that the jinja2 template portion for the plugin did not work. Once I made the changes in this pull request it worked as expected for the auth_token. |
Please share how exactly you are using this inventory plugin. PS: it would be nice if you created an Issue for this before submitting this PR, in my opinion Issues is much better place to discuss "issues" -) |
Freshly deployed Zabbix, has only one host.
|
Sure I can do that apologies as first time trying to contribute here. I will try and raise the issue late today. |
Yes that option will work, but using jinja2 in the inventory file would be a nice option in my opinion. Such as: |
Ok, I have tested and your PR does not break anything but brings new functionality. I am ok with that. Please provide changelog fragment and we'll merge this PR. Thanks! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1342 +/- ##
==========================================
+ Coverage 75.28% 76.45% +1.17%
==========================================
Files 44 43 -1
Lines 5523 5445 -78
Branches 1410 1396 -14
==========================================
+ Hits 4158 4163 +5
+ Misses 859 814 -45
+ Partials 506 468 -38 ☔ View full report in Codecov by Sentry. |
Thanks, I believe I have added the changelog fragment correctly. Is there still a need to open an issue for this PR or should I just remember for next time? |
Just remember for the next time. |
SUMMARY
This allows for jinja2 templating to be used in the zabbix_inventory plugin so that the auth_token value can be protected with an environment variable or ansible-vault file. Without this you are forced to add your API token in clear text in the configuration file which is not ideal for security.
ISSUE TYPE
COMPONENT NAME
community.zabbix.zabbix_inventory
ADDITIONAL INFORMATION
Credit for the code goes to contributers to the digitalocean inventory plugin where they have this feature implemented.
I have not been successful in getting my development environment / integration tests working at the moment but this has been manually tested and it works as intended.