Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended docs and examples for multiple assign_filter conditions #227

Merged
merged 5 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", ]'
Loading