-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add Icinga Deploy handler and module #205
Conversation
Codecov Report
@@ Coverage Diff @@
## master #205 +/- ##
==========================================
- Coverage 97.25% 96.01% -1.25%
==========================================
Files 41 43 +2
Lines 1094 1154 +60
Branches 171 180 +9
==========================================
+ Hits 1064 1108 +44
- Misses 16 28 +12
- Partials 14 18 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
|
…nt deploy and deployment info module
plugins/modules/icinga_deploy.py
Outdated
RETURN = r""" # """ | ||
|
||
from ansible.module_utils.urls import url_argument_spec | ||
from ansible.module_utils.basic import AnsibleModule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from ansible.module_utils.basic import AnsibleModule | |
from ansible.module_utils.basic import AnsibleModule |
plugins/modules/icinga_deploy.py
Outdated
# Define the main module | ||
module = AnsibleModule( | ||
argument_spec=argument_spec, | ||
supports_check_mode=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
supports_check_mode=True, | |
supports_check_mode=False, |
module: icinga_deploy | ||
short_description: Trigger deployment in Icinga2 | ||
description: | ||
- Trigger a deployment to Icinga2 through the director API. | ||
author: Falk Händler (@flkhndlr) | ||
version_added: '1.33.0' | ||
extends_documentation_fragment: | ||
- ansible.builtin.url | ||
- t_systems_mms.icinga_director.common_options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
module: icinga_deploy | |
short_description: Trigger deployment in Icinga2 | |
description: | |
- Trigger a deployment to Icinga2 through the director API. | |
author: Falk Händler (@flkhndlr) | |
version_added: '1.33.0' | |
extends_documentation_fragment: | |
- ansible.builtin.url | |
- t_systems_mms.icinga_director.common_options | |
module: icinga_deploy_info | |
short_description: Query deployment information in Icinga2 | |
description: | |
- Get deployment information through the director API. | |
author: Falk Händler (@flkhndlr) | |
version_added: '1.33.0' | |
extends_documentation_fragment: | |
- ansible.builtin.url | |
- t_systems_mms.icinga_director.common_options |
""" | ||
|
||
RETURN = r""" | ||
config: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When querying the API, the director returns an object called active_configuration
. Let's try to stick to this. So I propose to rename config
to active_configuration
.
query=dict(type="str", required=False, default=""), | ||
resolved=dict(type="bool", default=False, choices=[True, False]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These seem to be unused.
query=dict(type="str", required=False, default=""), | |
resolved=dict(type="bool", default=False, choices=[True, False]), |
url_username: "{{ icinga_user }}" | ||
url_password: "{{ icinga_pass }}" | ||
when: icinga_deploy_config and icinga_deploy_config is defined | ||
run_once: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handlers always run once.
run_once: true |
url_username: "{{ icinga_user }}" | ||
url_password: "{{ icinga_pass }}" | ||
when: icinga_deploy_config and icinga_deploy_config is defined | ||
run_once: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handlers always run once.
run_once: true |
object_list = icinga_object.query() | ||
|
||
module.exit_json( | ||
config=object_list["data"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now we return an object called config
that contains a dict called active_configuration
that then contains the actual data:
ok: [localhost] => {"changed": false, "config": {"active_configuration": {"activity": "a4c955364bc7b77efd0323fc87d95307f827e30c", "config": "b175ca0562434deeb4fb1fc03fd80cd7361b56df", "stage_name": "5e4ee411-dff9-
461e-b530-a6da21cc070e"}}}
Let's try to remove that indirection by directly returning the contents of active_configuration
. We can achieve that by doing this:
config=object_list["data"], | |
config=object_list["data"]["active_configuration"], |
Then we get back this:
ok: [localhost] => {"active_configuration": {"activity": "a4c955364bc7b77efd0323fc87d95307f827e30c", "config": "b175ca0562434deeb4fb1fc03fd80cd7361b56df", "stage_name": "5e4ee411-dff9-461e-b530-a6da21cc070e"}, "changed": false}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats a good idea, but one thing I noticed was, that the automatic testgeneration wants "objects" as the key. So I changed it to objects rather than active_configuration. If we want to update the testgeneration, I'm open to it :)
…ng-deploy-handler
This PR adds a module and handler to trigger a deployment of the Icinga config. Tasks are updated to call the handler.
The default behavior is not changed, so that current users are not confronted with changes in execution.
I'm not sure how to integrate testing for the handler and how to document the usage in a correct way.
Thanks in advance.
This PR resolves Part of #90.