-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
icinga2_host: make use of templates and template vars #6286
Conversation
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.
Thanks for your contribution! Please add a changelog fragment. Thanks.
I'm not familiar with icinga2 at all, but this looks to me that the format icinga2 wants changed over time. So probably this needs a version check so that it won't break for older versions which require the old format.
Changelog fragment is done! From what I'm seeing, the possibility to control hosts via Icinga API has been documented since 2015 and the format has stayed the same since. See the first draft of the Icinga API documentation, from 2015. |
changelogs/fragments/6286-icinga2_host-template-and-template-vars.yml
Outdated
Show resolved
Hide resolved
The module was added in Ansible 2.5.0 (released 2018) in ansible/ansible#31720. The documentation around that time looked like this: https://github.com/Icinga/icinga2/blob/ec061a95381ed37b18b3bf70ae6bade3203753ba/doc/12-icinga2-api.md#creating-config-objects- This coindices with the draft you found. Interestingly the module seems to have worked, or at least partially - I found ansible/ansible#49789, which also did some of the changes you're doing now, and a lot of other things as well - unfortunately it never got merged. |
…ars.yml Co-authored-by: Felix Fontein <[email protected]>
Indeed, this previous PR ansible/ansible#49789 was interesting... |
If nobody objects, I'll merge this in a couple of days. |
Backport to stable-5: 💚 backport PR created✅ Backport PR branch: Backported as #6374 🤖 @patchback |
* icinga2_host: make use of templates, append vars instead of replacing all vars array. * Initialize `template` variable. Add changelog fragment. * Update changelogs/fragments/6286-icinga2_host-template-and-template-vars.yml Co-authored-by: Felix Fontein <[email protected]> --------- Co-authored-by: Felix Fontein <[email protected]> (cherry picked from commit 76dd465)
Backport to stable-6: 💚 backport PR created✅ Backport PR branch: Backported as #6375 🤖 @patchback |
@yoannlr thanks for your contribution! |
* icinga2_host: make use of templates, append vars instead of replacing all vars array. * Initialize `template` variable. Add changelog fragment. * Update changelogs/fragments/6286-icinga2_host-template-and-template-vars.yml Co-authored-by: Felix Fontein <[email protected]> --------- Co-authored-by: Felix Fontein <[email protected]> (cherry picked from commit 76dd465)
Thanks a lot @yoannlr @felixfontein ! I really appreciate it and will test this asap. |
…lates and template vars (#6374) icinga2_host: make use of templates and template vars (#6286) * icinga2_host: make use of templates, append vars instead of replacing all vars array. * Initialize `template` variable. Add changelog fragment. * Update changelogs/fragments/6286-icinga2_host-template-and-template-vars.yml Co-authored-by: Felix Fontein <[email protected]> --------- Co-authored-by: Felix Fontein <[email protected]> (cherry picked from commit 76dd465) Co-authored-by: yoannlr <[email protected]>
…lates and template vars (#6375) icinga2_host: make use of templates and template vars (#6286) * icinga2_host: make use of templates, append vars instead of replacing all vars array. * Initialize `template` variable. Add changelog fragment. * Update changelogs/fragments/6286-icinga2_host-template-and-template-vars.yml Co-authored-by: Felix Fontein <[email protected]> --------- Co-authored-by: Felix Fontein <[email protected]> (cherry picked from commit 76dd465) Co-authored-by: yoannlr <[email protected]>
SUMMARY
Currently, the
template
parameter of the icinga2_host module is not sent correctly to Icinga, which results in the impossibility to use host templates when using this module.This is due to an incorrect data structure, see this example with curl for the correct data structure.
This PR fixes it by submitting the correct data structure to the Icinga API.
This PR also enables inheritance of the template vars to the created host. In the current code, the whole
vars
array is sent to Icinga, which causes Icinga to ignore vars declared in the template. In this PR's code, thevars
array is not redefined, each variable is send to Icinga asvars.key = value
:Current code :
vars = { distro = Debian } // redefines the vars array, we lose the template vars
PR's code:
vars.distro = Debian // append vars.distro to the vars array, we keep inherited vars
Fixes #3905.
ISSUE TYPE
COMPONENT NAME
icinga2_host module
ADDITIONAL INFORMATION