Skip to content
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

Merged
merged 3 commits into from
Apr 20, 2023

Conversation

yoannlr
Copy link
Contributor

@yoannlr yoannlr commented Apr 4, 2023

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, the vars array is not redefined, each variable is send to Icinga as vars.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
  • Bugfix Pull Request
COMPONENT NAME

icinga2_host module

ADDITIONAL INFORMATION

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module monitoring new_contributor Help guide this first time contributor plugins plugin (any type) labels Apr 4, 2023
@yoannlr yoannlr changed the title icinga2_host: make use of templates, append vars instead of replacing the whole vars array icinga2_host: make use of templates and template vars Apr 4, 2023
Copy link
Collaborator

@felixfontein felixfontein left a 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.

@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-5 labels Apr 5, 2023
@yoannlr
Copy link
Contributor Author

yoannlr commented Apr 5, 2023

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.

@felixfontein
Copy link
Collaborator

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.

@yoannlr
Copy link
Contributor Author

yoannlr commented Apr 5, 2023

Indeed, this previous PR ansible/ansible#49789 was interesting...
All of the parameters it added can (probably should) however be defined in templates.

@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Apr 13, 2023
@felixfontein
Copy link
Collaborator

If nobody objects, I'll merge this in a couple of days.

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Apr 20, 2023
@felixfontein felixfontein merged commit 76dd465 into ansible-collections:main Apr 20, 2023
@patchback
Copy link

patchback bot commented Apr 20, 2023

Backport to stable-5: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-5/76dd465e082a8b0b7af597fbfdcde0852292887a/pr-6286

Backported as #6374

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Apr 20, 2023
* 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)
@patchback
Copy link

patchback bot commented Apr 20, 2023

Backport to stable-6: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-6/76dd465e082a8b0b7af597fbfdcde0852292887a/pr-6286

Backported as #6375

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@felixfontein
Copy link
Collaborator

@yoannlr thanks for your contribution!

patchback bot pushed a commit that referenced this pull request Apr 20, 2023
* 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)
@MarcusCaepio
Copy link

Thanks a lot @yoannlr @felixfontein ! I really appreciate it and will test this asap.

felixfontein pushed a commit that referenced this pull request Apr 20, 2023
…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]>
felixfontein pushed a commit that referenced this pull request Apr 20, 2023
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug module module monitoring new_contributor Help guide this first time contributor plugins plugin (any type) stale_ci CI is older than 7 days, rerun before merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

community.general.icinga2_host - including template not working
4 participants