Skip to content

Commit

Permalink
Increase sleep to 5 seconds (#245)
Browse files Browse the repository at this point in the history
* Increase sleep to 5 seconds

Deployments run successfully, but there are not reported correctly in Ansible. So a timeout increase is one option

* adding variable timeout in role and script

* add documentation

* add changes to pass sanity check

adding typing

* add example, change example in plugin, add test

---------

Co-authored-by: Sebastian Gumprich <[email protected]>
  • Loading branch information
flkhndlr and rndmh3ro authored Feb 13, 2024
1 parent 423484b commit a811165
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/icinga_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
url: "{{ icinga_url }}"
url_username: "{{ icinga_user }}"
url_password: "{{ icinga_pass }}"
timeout: 5
12 changes: 10 additions & 2 deletions plugins/modules/icinga_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
extends_documentation_fragment:
- ansible.builtin.url
- telekom_mms.icinga_director.common_options
options:
timeout:
description:
- Default timeout to wait for deployment to finish in seconds.
default: 2
type: int
"""

EXAMPLES = """
Expand All @@ -40,6 +46,7 @@
url: "{{ icinga_url }}"
url_username: "{{ icinga_user }}"
url_password: "{{ icinga_pass }}"
timeout: 5
"""

RETURN = r"""
Expand Down Expand Up @@ -71,6 +78,7 @@ def main():
# add our own arguments
argument_spec.update(
url=dict(required=True),
timeout=dict(required=False, default=2, type="int")
)

# Define the main module
Expand All @@ -92,8 +100,8 @@ def main():
icinga_deployment = Icinga2APIObject(module=module, path="/config/deploy", data=[])
result = icinga_deployment.create()
# the deployment is asynchronous and I don't know of a way to check if it is finished.
# so we need some sleep here. 2 seconds is a wild guess.
sleep(2)
# so we need some sleep here. 2 seconds is a wild guess and a default, now it is a variable
sleep(module.params["timeout"])

# get the new deployment status
create_deployment = icinga_deploy_status.query_deployment()["data"]["active_configuration"]["config"]
Expand Down
1 change: 1 addition & 0 deletions roles/ansible_icinga/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
client_key: "{{ icinga_client_key | default(omit) }}"
url_username: "{{ icinga_user }}"
url_password: "{{ icinga_pass }}"
timeout: "{{ icinga_deploy_timeout | default(omit) }}"
when: icinga_deploy_config and icinga_deploy_config is defined
listen: config_deploy
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
url: "{{ icinga_url }}"
url_username: "{{ icinga_user }}"
url_password: "{{ icinga_pass }}"
timeout: 5
when: icinga_deploy_config and icinga_deploy_config is defined
listen: config_deploy
listen: config_deploy

0 comments on commit a811165

Please sign in to comment.