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

Added redirect option for activation endpoint #479

Merged
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
37 changes: 27 additions & 10 deletions plugins/modules/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
extends_documentation_fragment: [checkmk.general.common]

options:
redirect:
description:
- If set to C(true), wait for the activation to complete.
If set to C(false), start the activation, but do not wait for it to finish.
default: false
type: bool
sites:
description: The sites that should be activated. Omitting this option activates all sites.
default: []
Expand All @@ -38,15 +44,15 @@
"""

EXAMPLES = r"""
- name: "Activate changes on all sites."
- name: "Start activation on all sites."
checkmk.general.activation:
server_url: "http://localhost/"
site: "my_site"
automation_user: "automation"
automation_secret: "$SECRET"
run_once: 'true'

- name: "Activate changes on a specific site."
- name: "Start activation on a specific site."
checkmk.general.activation:
server_url: "http://localhost/"
site: "my_site"
Expand All @@ -56,12 +62,22 @@
- "my_site"
run_once: 'true'

- name: "Activate changes including foreign changes."
- name: "Start activation including foreign changes."
checkmk.general.activation:
server_url: "http://localhost/"
site: "my_site"
automation_user: "automation"
automation_secret: "$SECRET"
force_foreign_changes: 'true'
run_once: 'true'

- name: "Activate changes including foreign changes and wait for completion."
checkmk.general.activation:
server_url: "http://localhost/"
site: "my_site"
automation_user: "automation"
automation_secret: "$SECRET"
redirect: 'true'
force_foreign_changes: 'true'
run_once: 'true'
"""
Expand All @@ -76,7 +92,7 @@
description: The output message that the module generates.
type: str
returned: always
sample: 'Changes activated.'
sample: 'Activation started.'
"""

import time
Expand All @@ -89,25 +105,25 @@

HTTP_CODES = {
# http_code: (changed, failed, "Message")
200: (True, False, "Changes activated."),
204: (True, False, "Changes activated."),
200: (True, False, "Activation started."),
204: (True, False, "Activation has been completed."),
302: (True, False, "Redirected."),
422: (False, False, "There are no changes to be activated."),
401: (
False,
True,
"Unauthorized: There are foreign changes, which you may not activate, or you did not use <force_foreign_changes>.",
"There are foreign changes, which you do not have permission to activate, or you did not use <force_foreign_changes>.",
),
409: (False, True, "Conflict: Some sites could not be activated."),
423: (False, True, "Locked: There is already an activation running."),
409: (False, True, "Some sites could not be activated."),
423: (False, True, "There is already an activation running."),
}


class ActivationAPI(CheckmkAPI):
def post(self):
data = {
"force_foreign_changes": self.params.get("force_foreign_changes"),
"redirect": False,
"redirect": self.params.get("redirect"),
"sites": self.params.get("sites", []),
}

Expand All @@ -129,6 +145,7 @@ def run_module():
automation_secret=dict(type="str", required=True, no_log=True),
sites=dict(type="raw", default=[]),
force_foreign_changes=dict(type="bool", default=False),
redirect=dict(type="bool", default=False),
)
module = AnsibleModule(argument_spec=module_args, supports_check_mode=False)

Expand Down
1 change: 1 addition & 0 deletions roles/agent/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
automation_user: "{{ checkmk_agent_user }}"
automation_secret: "{{ checkmk_agent_auth }}"
force_foreign_changes: "{{ checkmk_agent_force_foreign_changes }}"
redirect: 'true'
validate_certs: "{{ checkmk_agent_server_validate_certs }}"
delegate_to: "{{ checkmk_agent_delegate_api_calls }}"
run_once: true # noqa run-once[task]
Expand Down
4 changes: 0 additions & 4 deletions roles/agent/tasks/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@
block:
- name: "Trigger activation of changes."
ansible.builtin.meta: flush_handlers
# ToDo: We should get rid of the following, once we can query the running activation process to know when it is fnished.
- name: "Give the activation process time to finish."
ansible.builtin.pause:
seconds: 30

- name: "{{ ansible_system }}: Check for Agent Updater Binary."
ansible.builtin.stat:
Expand Down
4 changes: 0 additions & 4 deletions roles/agent/tasks/Win32NT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
block:
- name: "Trigger activation of changes."
ansible.builtin.meta: flush_handlers
# ToDo: We should get rid of the following, once we can query the running activation process to know when it is fnished.
- name: "Give the activation process time to finish."
ansible.builtin.pause:
seconds: 30

- name: "Check for Agent Controller Binary."
ansible.windows.win_stat:
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/targets/activation/tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,16 @@
delegate_to: localhost
run_once: true # noqa run-once[task]
loop: "{{ checkmk_hosts }}"

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Activate with explicit site and redirect."
activation:
server_url: "{{ server_url }}"
site: "{{ outer_item.site }}"
automation_user: "{{ automation_user }}"
automation_secret: "{{ automation_secret }}"
redirect: 'true'
force_foreign_changes: 'false'
sites:
- "{{ outer_item.site }}"
delegate_to: localhost
run_once: true # noqa run-once[task]
4 changes: 2 additions & 2 deletions tests/integration/targets/activation/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
test_sites:
- version: "2.2.0p12"
- version: "2.2.0p14"
edition: "cre"
site: "stable_raw"
- version: "2.2.0p12"
- version: "2.2.0p14"
edition: "cee"
site: "stable_ent"
- version: "2.1.0p35"
Expand Down