From 11c1580b23e68a1ca7f6accb9aff0e36d5f6c348 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 14 Jan 2019 21:37:23 +0100 Subject: [PATCH] [2.7] icinga2_host: fix use_proxy option (#50865) * fix use_proxy option in icinga2_host (#47671) (cherry picked from commit e7b91f331b2400203db58b2c84c46bb8a3efe424) * Move changelog fragment to changelogs/fragments/. --- .../fragments/icinga2_host-47671-fix-use_proxy.yaml | 2 ++ lib/ansible/modules/monitoring/icinga2_host.py | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/icinga2_host-47671-fix-use_proxy.yaml diff --git a/changelogs/fragments/icinga2_host-47671-fix-use_proxy.yaml b/changelogs/fragments/icinga2_host-47671-fix-use_proxy.yaml new file mode 100644 index 00000000000..b5238b7772b --- /dev/null +++ b/changelogs/fragments/icinga2_host-47671-fix-use_proxy.yaml @@ -0,0 +1,2 @@ +bugfixes: +- icinga2_host - fixed the issue with not working ``use_proxy`` option of the module. diff --git a/lib/ansible/modules/monitoring/icinga2_host.py b/lib/ansible/modules/monitoring/icinga2_host.py index c0b7701172e..cca8026e2a8 100644 --- a/lib/ansible/modules/monitoring/icinga2_host.py +++ b/lib/ansible/modules/monitoring/icinga2_host.py @@ -134,13 +134,16 @@ from ansible.module_utils.urls import fetch_url, url_argument_spec class icinga2_api: module = None + def __init__(self, module): + self.module = module + def call_url(self, path, data='', method='GET'): headers = { 'Accept': 'application/json', 'X-HTTP-Method-Override': method, } url = self.module.params.get("url") + "/" + path - rsp, info = fetch_url(module=self.module, url=url, data=data, headers=headers, method=method) + rsp, info = fetch_url(module=self.module, url=url, data=data, headers=headers, method=method, use_proxy=self.module.params['use_proxy']) body = '' if rsp: body = json.loads(rsp.read()) @@ -248,8 +251,7 @@ def main(): variables = module.params["variables"] try: - icinga = icinga2_api() - icinga.module = module + icinga = icinga2_api(module=module) icinga.check_connection() except Exception as e: module.fail_json(msg="unable to connect to Icinga. Exception message: %s" % (e))