Added new feature for ansible_user and ansible_port in Icinga2 inventory source (#4088)

* Added new feature for ansible_user and ansible_port

* Replaced 'try' and 'except' with 'if' condition

* Replace '!=' with 'is not'

* Fixed if condition

* Implement the constructed interface

* Correction at the suggestion of felixfontein

* Added new options in unit test for icinga2 inventory

* Added blank lines in unit test for icinga2 inventory

* Added default filter in example

Co-authored-by: Felix Fontein <felix@fontein.de>

* Fixed variable name in example

Co-authored-by: Felix Fontein <felix@fontein.de>

* Added a changelog fragment

* Fixed changelog fragment

Co-authored-by: Felix Fontein <felix@fontein.de>

* Updated documentation options

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Nedelin Petkov 2022-01-31 20:50:08 +02:00 committed by GitHub
parent 5710faab64
commit 969ad475e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 1 deletions

View file

@ -76,6 +76,19 @@ def query_hosts(hosts=None, attrs=None, joins=None, host_filter=None):
return json_host_data
def get_option(option):
if option == 'groups':
return {}
elif option == 'keyed_groups':
return []
elif option == 'compose':
return {}
elif option == 'strict':
return False
else:
return None
def test_populate(inventory, mocker):
# module settings
inventory.icinga2_user = 'ansible'
@ -86,6 +99,7 @@ def test_populate(inventory, mocker):
# bypass authentication and API fetch calls
inventory._check_api = mocker.MagicMock(side_effect=check_api)
inventory._query_hosts = mocker.MagicMock(side_effect=query_hosts)
inventory.get_option = mocker.MagicMock(side_effect=get_option)
inventory._populate()
# get different hosts