Skip to content

Commit

Permalink
Extended docs and examples for multiple assign_filter conditions (#227)
Browse files Browse the repository at this point in the history
* added example for multiple conditions

* added example for multiple condition

* added assign_filter info

* add existing variable so plays run

* beautify readme

---------

Co-authored-by: Sebastian Gumprich <[email protected]>
  • Loading branch information
log1-c and rndmh3ro authored Nov 13, 2023
1 parent 5ebedd5 commit 3b3cf30
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
11 changes: 11 additions & 0 deletions examples/icinga_hostgroup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions plugins/modules/icinga_hostgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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""" # """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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: <urlopen error [Errno -3] Temporary failure in name resolution>", "bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>", "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: <urlopen error [Errno -3] Temporary failure in name resolution>", "bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>", "bad return code while querying: 401. Error message: HTTP Error 401: Unauthorized", ]'
Original file line number Diff line number Diff line change
Expand Up @@ -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: <urlopen error [Errno -3] Temporary failure in name resolution>", "bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>", "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: <urlopen error [Errno -3] Temporary failure in name resolution>", "bad return code while creating: -1. Error message: Request failed: <urlopen error [Errno -2] Name or service not known>", "bad return code while querying: 401. Error message: HTTP Error 401: Unauthorized", ]'

0 comments on commit 3b3cf30

Please sign in to comment.