community.general icon indicating copy to clipboard operation
community.general copied to clipboard

Adds group_by_hostgroups parameter to Icinga2 inventory

Open Gianlu opened this issue 1 year ago • 10 comments

SUMMARY

This PR adds an optional parameter to Icinga2 inventory group_by_hostgroups (boolean). If true, Icinga2 hostgroups are used as Ansible groups; if false the step is ignored. For backward compatibility, the default is true.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

icinga2.py inventory

ADDITIONAL INFORMATION

In my use case, I want to use Icinga2 as inventory source but my hostgroups' naming convention isn't suitable to become an ansible group strategy (spaces, capital letters and invalid characters) so I prefer to disable the builtin grouping by hostgroups and use the capabilities of constructed inventory (groups and keyed_groups).

# my.icinga2.yml
plugin: community.general.icinga2
url: http://localhost:5665
user: ansible
password: secure
host_filter: \"linux-servers\" in host.groups
validate_certs: false  # only do this when connecting to localhost!
group_by_hostgroups: false

Gianlu avatar Feb 21 '24 07:02 Gianlu

cc @BongoEADGC6 click here for bot help

ansibullbot avatar Feb 21 '24 07:02 ansibullbot

@Gianlu please note that there is a conflict you need to resolve. (Please use a rebase for that, not a merge commit.)

felixfontein avatar Feb 26 '24 19:02 felixfontein

@Gianlu this PR contains the following merge commits:

  • https://github.com/ansible-collections/community.general/commit/da155ef80585270a15d33fdb37249324579eeebd

Please rebase your branch to remove these commits.

click here for bot help

ansibullbot avatar Feb 26 '24 19:02 ansibullbot

The test ansible-test sanity --test pylint [explain] failed with 1 error:

plugins/inventory/icinga2.py:303:0: trailing-whitespace: Trailing whitespace

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

plugins/inventory/icinga2.py:303:1: W293: blank line contains whitespace

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

plugins/inventory/icinga2.py:303:1: W293: blank line contains whitespace

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

plugins/inventory/icinga2.py:303:1: W293: blank line contains whitespace

The test ansible-test sanity --test pylint [explain] failed with 1 error:

plugins/inventory/icinga2.py:303:0: trailing-whitespace: Trailing whitespace

The test ansible-test sanity --test pylint [explain] failed with 1 error:

plugins/inventory/icinga2.py:303:0: trailing-whitespace: Trailing whitespace

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

plugins/inventory/icinga2.py:303:1: W293: blank line contains whitespace

The test ansible-test sanity --test pylint [explain] failed with 1 error:

plugins/inventory/icinga2.py:303:0: trailing-whitespace: Trailing whitespace

click here for bot help

ansibullbot avatar Feb 26 '24 19:02 ansibullbot

@Gianlu this PR contains the following merge commits:

  • https://github.com/ansible-collections/community.general/commit/da155ef80585270a15d33fdb37249324579eeebd
  • https://github.com/ansible-collections/community.general/commit/2a3e8da0fd095fabc06cca50da5819a7edc1eae2
  • https://github.com/ansible-collections/community.general/commit/ecdb3a9eacec7f9c21cdb342968286f44583ead6

Please rebase your branch to remove these commits.

click here for bot help

ansibullbot avatar Feb 26 '24 19:02 ansibullbot

@Gianlu this PR contains the following merge commits:

  • https://github.com/ansible-collections/community.general/commit/da155ef80585270a15d33fdb37249324579eeebd
  • https://github.com/ansible-collections/community.general/commit/2a3e8da0fd095fabc06cca50da5819a7edc1eae2
  • https://github.com/ansible-collections/community.general/commit/ecdb3a9eacec7f9c21cdb342968286f44583ead6
  • https://github.com/ansible-collections/community.general/commit/65d1319ce2ccc93c44c2e430780d7ad08d7312cd

Please rebase your branch to remove these commits.

click here for bot help

ansibullbot avatar Feb 26 '24 20:02 ansibullbot

The change looks good, but the commit history looks quite ... adventerous :) Would you mind cleaning it up a bit? Thanks!

felixfontein avatar Feb 28 '24 20:02 felixfontein

@Gianlu ping

felixfontein avatar Mar 10 '24 16:03 felixfontein

Hi, You are right: I didn't reply. Have I to squash? Or do you have a guide line I can follow?

Thanks

Gianlu avatar Mar 10 '24 16:03 Gianlu

In general squashing is not necessary since we squash on merge, but all your commit messages will end up in the PR's commit message, which currently would contain something like:

* Introduce 'group_by_hostgroups' parameter

* Added CHANGELOG fragment

* Rename changelog fragmment in order to include PR number

* Linting after CI failure

* Linting after CI failure (2)

* Linting after CI failure (3)

* Fix test

* Fixing tests (2)

* Update plugins/inventory/icinga2.py

* Update changelogs/fragments/7998-icinga2-inventory-group_by_hostgroup…

* Update plugins/inventory/icinga2.py

* Linting after CI failure

* Update plugins/inventory/icinga2.py

* Error due to rebase

* Introduce 'group_by_hostgroups' parameter

* Added CHANGELOG fragment

* Rename changelog fragmment in order to include PR number

* Linting after CI failure

* Linting after CI failure (2)

* Linting after CI failure (3)

* Update plugins/inventory/icinga2.py

* Update changelogs/fragments/7998-icinga2-inventory-group_by_hostgroup…

* Linting after CI failure

* Linting after CI failure (2)

* Update plugins/inventory/icinga2.py

* Update plugins/inventory/icinga2.py

* Error in merging

* Correct over indent

* Fragment

* Deleted temp file

I would squash at least some of them together (or even all if you don't want to invest much time in it).

felixfontein avatar Mar 10 '24 16:03 felixfontein

Backport to stable-8: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-8/4947786d3694bee0498c40b54540f67170518b70/pr-7998

Backported as https://github.com/ansible-collections/community.general/pull/8134

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

patchback[bot] avatar Mar 24 '24 17:03 patchback[bot]

@Gianlu thanks for your contribution.

felixfontein avatar Mar 24 '24 17:03 felixfontein