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

Improve idempotency of the registration tasks in the agent #615

Merged
merged 22 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fb309f2
First try at making the TLS registration idempotent.
robin-checkmk Jun 6, 2024
7d6cdf2
Add support for Windows.
robin-checkmk Jun 7, 2024
271425a
Add support for the agent updater.
robin-checkmk Jun 7, 2024
fd9d9ad
Merge branch 'devel' of github.com:Checkmk/ansible-collection-checkmk…
robin-checkmk Jun 7, 2024
9441a4e
Fix behavior when file is not found.
robin-checkmk Jun 7, 2024
2b363f2
Add `failed_when` so the task does not fail, even if the file does no…
robin-checkmk Jun 10, 2024
2686ebb
Merge branch 'feature/mark-internal-vars' into feature/agent-improve-…
robin-checkmk Jun 10, 2024
d6165a9
These tasks never change a thing, so we set appropriate changed_when …
robin-checkmk Jun 13, 2024
a6ac6df
Fix typo.
robin-checkmk Jun 13, 2024
efd510e
The modules to download web content on Windows and Linux use differen…
robin-checkmk Jun 13, 2024
d1f8eea
Fix typo.
robin-checkmk Jun 13, 2024
ae0239c
Merge branch 'devel' of github.com:Checkmk/ansible-collection-checkmk…
robin-checkmk Jun 13, 2024
28fc425
Add changelog.
robin-checkmk Jun 13, 2024
341b325
Merge branch 'devel' of github.com:Checkmk/ansible-collection-checkmk…
robin-checkmk Jun 13, 2024
6e48c2b
Merge branch 'feature/agent-improve-idempotency' into bugfix/setup-do…
robin-checkmk Jun 13, 2024
0ecb6f1
Merge branch 'devel' into feature/agent-improve-idempotency
robin-checkmk Jun 14, 2024
98765d7
Fix fail logic for Linux agent read updater task.
robin-checkmk Jun 14, 2024
fd19522
Merge branch 'feature/agent-improve-idempotency' of github.com:Checkm…
robin-checkmk Jun 14, 2024
6585633
Fix conditional.
robin-checkmk Jun 14, 2024
0a1edd3
Bugfix fail logic.
robin-checkmk Jun 14, 2024
dca1703
Merge pull request #623 from Checkmk/bugfix/setup-download-status
robin-checkmk Jun 14, 2024
d51026c
Add changelog.
robin-checkmk Jun 14, 2024
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ The following are guidelines to keep in mind, when creating or changing roles an
- `checkmk_server_foo` for a server role variable
- `checkmk_agent_bar` for a agent role variable
- `checkmk_var_bat` for general variables
- Internal variables, not intended to be changed by a user should be prefixed with a double underscore (`__`).
- Internal variables, not intended to be changed by a user should be prefixes with a double underscore (`__`).
- Tags
- When tagging roles or playbooks, separate single words with dashes (`my-custom-tag`)

Expand Down
15 changes: 15 additions & 0 deletions roles/agent/tasks/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
path: /usr/bin/cmk-agent-ctl
register: __checkmk_agent_controller_binary

- name: "{{ ansible_system }}: Read Agent Controller State." # noqa no-changed-when
become: true
ansible.builtin.command: cat /var/lib/cmk-agent/registered_connections.json
register: __checkmk_agent_registered_connections

- name: "{{ ansible_system }}: Read Updater State." # noqa no-changed-when
become: true
ansible.builtin.command: cat /var/lib/check_mk_agent/cache/plugins_cmk-update-agent.cache
register: __checkmk_agent_updater_state
changed_when: checkmk_agent_registration_server + '/' + checkmk_agent_registration_site in __checkmk_agent_updater_state.stdout
failed_when: __checkmk_agent_updater_state.rc == "255"

- name: "{{ ansible_system }}: Register Agent for automatic Updates using User Password." # noqa no-changed-when
become: true
ansible.builtin.shell: |
Expand All @@ -101,6 +113,7 @@
and checkmk_agent_update | bool
and (checkmk_agent_pass is defined and checkmk_agent_pass | length)
and (checkmk_agent_secret is not defined)
and not checkmk_agent_registration_server + '/' + checkmk_agent_registration_site in __checkmk_agent_updater_state.stdout

- name: "{{ ansible_system }}: Register Agent for automatic Updates using Automation Secret." # noqa no-changed-when
become: true
Expand All @@ -115,6 +128,7 @@
and __checkmk_agent_updater_binary.stat.exists | bool
and checkmk_agent_update | bool
and (checkmk_agent_secret is defined and checkmk_agent_secret | length)
and not checkmk_agent_registration_server + '/' + checkmk_agent_registration_site in __checkmk_agent_updater_state.stdout

- name: "{{ ansible_system }}: Register Agent for TLS." # noqa no-changed-when
become: true
Expand All @@ -128,6 +142,7 @@
__checkmk_agent_controller_binary.stat.exists | bool
and checkmk_agent_tls | bool
and (__checkmk_agent_auth is defined and __checkmk_agent_auth | length)
and not checkmk_agent_registration_server + '/' + checkmk_agent_registration_site in __checkmk_agent_registered_connections.stdout

- name: "{{ ansible_system }}: Verify Checkmk Agent Port is open."
ansible.builtin.wait_for:
Expand Down
15 changes: 15 additions & 0 deletions roles/agent/tasks/Win32NT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
path: "{{ __checkmk_agent_binary_path }}"
register: __checkmk_agent_binary

- name: "{{ ansible_system }}: Read Agent Controller State." # noqa no-changed-when
ansible.windows.win_command: powershell.exe -
args:
stdin: Get-Content -ErrorAction Ignore -LiteralPath C:\ProgramData\checkmk\agent\registered_connections.json ; Exit 0
register: __checkmk_agent_registered_connections

- name: "{{ ansible_system }}: Read Updater State." # noqa no-changed-when
ansible.windows.win_command: powershell.exe -
args:
stdin: Get-Content -ErrorAction Ignore -LiteralPath C:\ProgramData\checkmk\agent\config\cmk-update-agent.state ; Exit 0
register: __checkmk_agent_updater_state

- name: "{{ ansible_system }}: Register Agent for automatic Updates using User Password." # noqa no-changed-when
ansible.windows.win_command: |
check_mk_agent.exe updater register -H {{ checkmk_agent_host_name }} \
Expand All @@ -55,6 +67,7 @@
and checkmk_agent_update | bool
and (checkmk_agent_pass is defined and checkmk_agent_pass | length)
and (checkmk_agent_secret is not defined)
and not '\'server\': \'' + checkmk_agent_registration_server + '\', \'site\': \'' + checkmk_agent_registration_site + '\'' in __checkmk_agent_updater_state.stdout

- name: "{{ ansible_system }}: Register Agent for automatic Updates using Automation Secret." # noqa no-changed-when
ansible.windows.win_command: |
Expand All @@ -70,6 +83,7 @@
and __checkmk_agent_binary.stat.exists | bool
and checkmk_agent_update | bool
and (checkmk_agent_secret is defined and checkmk_agent_secret | length)
and not '\'server\': \'' + checkmk_agent_registration_server + '\', \'site\': \'' + checkmk_agent_registration_site + '\'' in __checkmk_agent_updater_state.stdout

- name: "Trigger Activate Changes to enable TLS registration."
ansible.builtin.meta:
Expand All @@ -88,6 +102,7 @@
__checkmk_agent_controller_binary.stat.exists | bool
and checkmk_agent_tls | bool
and (__checkmk_agent_auth is defined and __checkmk_agent_auth | length)
and not checkmk_agent_registration_server + '/' + checkmk_agent_registration_site in __checkmk_agent_registered_connections.stdout

- name: "{{ ansible_system }}: Verify Checkmk Agent Port is open."
ansible.windows.win_wait_for:
Expand Down
Loading