diff --git a/README.md b/README.md index 097ee58f..199774ae 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,22 @@ With ansible-core >= 2.12 it is possible to specify defaults parameters for all command: my-command.sh ``` +## Examples for defining multiple assign_filter conditions + +The Icinga Director API expects multiple conditions for the `assign_filter` in a different format than what is rendered to the configuration files. + +Example: An assign condition in the config looking like this: + +``` +assign where host.vars.something == "foo" || host.vars.something_else == "bar" +``` + +would have to look like this when using the module: + +``` +assign_filter: 'host.vars.something="foo"|host.vars.something_else="bar"' +``` + ## Contributing See [Contributing](CONTRIBUTING.md). diff --git a/examples/icinga_hostgroup.yml b/examples/icinga_hostgroup.yml index 31d38f54..d67a680e 100644 --- a/examples/icinga_hostgroup.yml +++ b/examples/icinga_hostgroup.yml @@ -16,3 +16,14 @@ object_name: foohostgroup assign_filter: 'host.name="foohost"' append: true +- name: Update hostgroup using multiple contiditions in assign_filter + telekom_mms.icinga_director.icinga_hostgroup: + state: present + url: "{{ icinga_url }}" + url_username: "{{ icinga_user }}" + url_password: "{{ icinga_pass }}" + object_name: foohostgroup + assign_filter: 'host.vars.something="{{ your_var_here }}"|host.vars.something_else="anything"' + append: true + vars: + your_var_here: foo diff --git a/plugins/modules/icinga_hostgroup.py b/plugins/modules/icinga_hostgroup.py index a8416cc9..81486f39 100644 --- a/plugins/modules/icinga_hostgroup.py +++ b/plugins/modules/icinga_hostgroup.py @@ -86,6 +86,18 @@ object_name: foohostgroup assign_filter: 'host.name="foohost"' append: true + +- name: Update hostgroup using multiple contiditions in assign_filter + telekom_mms.icinga_director.icinga_hostgroup: + state: present + url: "{{ icinga_url }}" + url_username: "{{ icinga_user }}" + url_password: "{{ icinga_pass }}" + object_name: foohostgroup + assign_filter: 'host.vars.something="{{ your_var_here }}"|host.vars.something_else="anything"' + append: true + vars: + your_var_here: foo """ RETURN = r""" # """ diff --git a/tests/integration/targets/icinga/roles/icinga/tasks/absent_icinga_hostgroup.yml b/tests/integration/targets/icinga/roles/icinga/tasks/absent_icinga_hostgroup.yml index 0d674695..2c5d7396 100644 --- a/tests/integration/targets/icinga/roles/icinga/tasks/absent_icinga_hostgroup.yml +++ b/tests/integration/targets/icinga/roles/icinga/tasks/absent_icinga_hostgroup.yml @@ -16,3 +16,14 @@ object_name: foohostgroup assign_filter: 'host.name="foohost"' append: true +- name: Update hostgroup using multiple contiditions in assign_filter + telekom_mms.icinga_director.icinga_hostgroup: + state: absent + url: "{{ icinga_url }}" + url_username: "{{ icinga_user }}" + url_password: "{{ icinga_pass }}" + object_name: foohostgroup + assign_filter: 'host.vars.something="{{ your_var_here }}"|host.vars.something_else="anything"' + append: true + vars: + your_var_here: foo diff --git a/tests/integration/targets/icinga/roles/icinga/tasks/icinga_hostgroup.yml b/tests/integration/targets/icinga/roles/icinga/tasks/icinga_hostgroup.yml index 31d38f54..d67a680e 100644 --- a/tests/integration/targets/icinga/roles/icinga/tasks/icinga_hostgroup.yml +++ b/tests/integration/targets/icinga/roles/icinga/tasks/icinga_hostgroup.yml @@ -16,3 +16,14 @@ object_name: foohostgroup assign_filter: 'host.name="foohost"' append: true +- name: Update hostgroup using multiple contiditions in assign_filter + telekom_mms.icinga_director.icinga_hostgroup: + state: present + url: "{{ icinga_url }}" + url_username: "{{ icinga_user }}" + url_password: "{{ icinga_pass }}" + object_name: foohostgroup + assign_filter: 'host.vars.something="{{ your_var_here }}"|host.vars.something_else="anything"' + append: true + vars: + your_var_here: foo diff --git a/tests/integration/targets/icinga/roles/icinga/tasks/wrong_host_icinga_hostgroup.yml b/tests/integration/targets/icinga/roles/icinga/tasks/wrong_host_icinga_hostgroup.yml index 4008ff0e..4436ce86 100644 --- a/tests/integration/targets/icinga/roles/icinga/tasks/wrong_host_icinga_hostgroup.yml +++ b/tests/integration/targets/icinga/roles/icinga/tasks/wrong_host_icinga_hostgroup.yml @@ -30,3 +30,21 @@ - result.failed # yamllint disable-line rule:line-length - 'result.msg in [ "bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized", "bad return code while creating: -1. Error message: Request failed: ", "bad return code while creating: -1. Error message: Request failed: ", "bad return code while querying: 401. Error message: HTTP Error 401: Unauthorized", ]' +- name: Update hostgroup using multiple contiditions in assign_filter + telekom_mms.icinga_director.icinga_hostgroup: + state: present + url: http://nonexistent + url_username: "{{ icinga_user }}" + url_password: "{{ icinga_pass }}" + object_name: foohostgroup + assign_filter: 'host.vars.something="{{ your_var_here }}"|host.vars.something_else="anything"' + append: true + vars: + your_var_here: foo + ignore_errors: true + register: result +- assert: + that: + - result.failed + # yamllint disable-line rule:line-length + - 'result.msg in [ "bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized", "bad return code while creating: -1. Error message: Request failed: ", "bad return code while creating: -1. Error message: Request failed: ", "bad return code while querying: 401. Error message: HTTP Error 401: Unauthorized", ]' diff --git a/tests/integration/targets/icinga/roles/icinga/tasks/wrong_pass_icinga_hostgroup.yml b/tests/integration/targets/icinga/roles/icinga/tasks/wrong_pass_icinga_hostgroup.yml index 712b2e09..c6a9fc48 100644 --- a/tests/integration/targets/icinga/roles/icinga/tasks/wrong_pass_icinga_hostgroup.yml +++ b/tests/integration/targets/icinga/roles/icinga/tasks/wrong_pass_icinga_hostgroup.yml @@ -30,3 +30,21 @@ - result.failed # yamllint disable-line rule:line-length - 'result.msg in [ "bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized", "bad return code while creating: -1. Error message: Request failed: ", "bad return code while creating: -1. Error message: Request failed: ", "bad return code while querying: 401. Error message: HTTP Error 401: Unauthorized", ]' +- name: Update hostgroup using multiple contiditions in assign_filter + telekom_mms.icinga_director.icinga_hostgroup: + state: present + url: "{{ icinga_url }}" + url_username: "{{ icinga_user }}" + url_password: iamwrong + object_name: foohostgroup + assign_filter: 'host.vars.something="{{ your_var_here }}"|host.vars.something_else="anything"' + append: true + vars: + your_var_here: foo + ignore_errors: true + register: result +- assert: + that: + - result.failed + # yamllint disable-line rule:line-length + - 'result.msg in [ "bad return code while creating: 401. Error message: HTTP Error 401: Unauthorized", "bad return code while creating: -1. Error message: Request failed: ", "bad return code while creating: -1. Error message: Request failed: ", "bad return code while querying: 401. Error message: HTTP Error 401: Unauthorized", ]'