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

Release 3.1.0 #411

Merged
merged 159 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
155378f
WIP: Add Windows files.
robin-checkmk Sep 21, 2022
7c1a39d
Add and change files of agent role
muehlings Oct 14, 2022
db7ac5d
Add example playbooks and inventories
muehlings Oct 14, 2022
b114bcd
Add preparation files for Windows systems
muehlings Oct 14, 2022
cd4b127
Remove newlines
muehlings Nov 1, 2022
55ae6f3
Remove newlines
muehlings Nov 1, 2022
c266d28
Remove newline
muehlings Nov 1, 2022
4c56046
Change extension
muehlings Nov 1, 2022
da261e1
Update example-add_hosts.yml
muehlings Nov 1, 2022
0af6e66
Update 00-ansible.cmd
muehlings Nov 1, 2022
50b56dd
Update 01-winrm-quickconfig.cmd
muehlings Nov 1, 2022
7ed245b
Update Windows.yml
muehlings Nov 2, 2022
19e2590
Change -Path to -LiteralPath
muehlings Nov 2, 2022
2a9889a
Update 00-ansible.cmd
muehlings Nov 2, 2022
02332b0
Update .gitattributes
muehlings Nov 3, 2022
903f779
Update Linux.yml
muehlings Nov 3, 2022
0a5ef79
Update Windows.yml
muehlings Nov 3, 2022
0055678
Update example-linux-inventory.yml
muehlings Nov 3, 2022
7b43cc5
Update example-windows-inventory.yml
muehlings Nov 3, 2022
692b1f1
Update example-add_hosts.yml
muehlings Nov 3, 2022
2c7d9f1
Force LF line ending on windows files
muehlings Nov 3, 2022
a0c97ba
Update 00-ansible.cmd
muehlings Nov 3, 2022
dc35e44
Trash
robin-checkmk Nov 4, 2022
ea99fbb
Delete example-add_hosts.yml
muehlings Nov 7, 2022
b9101a0
Delete example-linux-inventory.yml
muehlings Nov 7, 2022
61a02f2
Delete example-windows-inventory.yml
muehlings Nov 7, 2022
c674f8a
Merge pull request #187 from muehlings/feature-agent-windows-support
robin-checkmk Nov 30, 2022
e153f6b
Merge branch 'feature-agent-windows-support' of github.com:tribe29/an…
robin-checkmk Nov 30, 2022
4bd13fa
Merge branch 'devel' of github.com:tribe29/ansible-collection-tribe29…
robin-checkmk Nov 30, 2022
e49d331
Fix main.yml after merges.
robin-checkmk Nov 30, 2022
ce45504
Clean up Jinja spacing in task names.
robin-checkmk Nov 30, 2022
64b8139
WIP: Add Windows files.
robin-checkmk Sep 21, 2022
de2f88d
Add and change files of agent role
muehlings Oct 14, 2022
adff725
Add example playbooks and inventories
muehlings Oct 14, 2022
c733671
Add preparation files for Windows systems
muehlings Oct 14, 2022
da20d22
Remove newlines
muehlings Nov 1, 2022
618b0b6
Remove newline
muehlings Nov 1, 2022
56908b9
Change extension
muehlings Nov 1, 2022
bd9295d
Update example-add_hosts.yml
muehlings Nov 1, 2022
af1fb84
Update 00-ansible.cmd
muehlings Nov 1, 2022
900524d
Update 01-winrm-quickconfig.cmd
muehlings Nov 1, 2022
8c0fd9a
Update Windows.yml
muehlings Nov 2, 2022
75c396a
Change -Path to -LiteralPath
muehlings Nov 2, 2022
2346eef
Update 00-ansible.cmd
muehlings Nov 2, 2022
65c2c8e
Update .gitattributes
muehlings Nov 3, 2022
f668adf
Update Linux.yml
muehlings Nov 3, 2022
ba18e5e
Update Windows.yml
muehlings Nov 3, 2022
5e7f164
Update example-linux-inventory.yml
muehlings Nov 3, 2022
cf5c248
Update example-windows-inventory.yml
muehlings Nov 3, 2022
c3190f4
Update example-add_hosts.yml
muehlings Nov 3, 2022
bb74f59
Force LF line ending on windows files
muehlings Nov 3, 2022
6b5d3d2
Update 00-ansible.cmd
muehlings Nov 3, 2022
8592c81
Trash
robin-checkmk Nov 4, 2022
cb044f1
Delete example-add_hosts.yml
muehlings Nov 7, 2022
c0b7d3e
Delete example-linux-inventory.yml
muehlings Nov 7, 2022
96fbb39
Delete example-windows-inventory.yml
muehlings Nov 7, 2022
6210508
Fix main.yml after merges.
robin-checkmk Nov 30, 2022
e352bff
Clean up Jinja spacing in task names.
robin-checkmk Nov 30, 2022
d9fb71c
Merge branch 'feature-agent-windows-support' of github.com:tribe29/an…
robin-checkmk Jan 16, 2023
e28ff54
Fix Jinja2 spacing.
robin-checkmk Jan 16, 2023
e0a4649
Fix too long lines.
robin-checkmk Jan 16, 2023
9e55097
Change -Path to -LiteralPath.
robin-checkmk Jan 16, 2023
c802a72
Add Windows vagrant box.
robin-checkmk Jan 16, 2023
42de2bc
Update Python dependencies.
robin-checkmk Jan 16, 2023
4532433
Clean up rebase gotchas.
robin-checkmk Jan 16, 2023
f80e057
WIP: Add Windows files.
robin-checkmk Sep 21, 2022
0396aa3
Add and change files of agent role
muehlings Oct 14, 2022
70705bd
Add example playbooks and inventories
muehlings Oct 14, 2022
8297e9b
Add preparation files for Windows systems
muehlings Oct 14, 2022
9d2030f
Remove newlines
muehlings Nov 1, 2022
9f65e6d
Remove newline
muehlings Nov 1, 2022
9d26c6e
Change extension
muehlings Nov 1, 2022
09a695f
Update example-add_hosts.yml
muehlings Nov 1, 2022
29b825e
Update 00-ansible.cmd
muehlings Nov 1, 2022
ae64e92
Update 01-winrm-quickconfig.cmd
muehlings Nov 1, 2022
8f18dc0
Update Windows.yml
muehlings Nov 2, 2022
64bc981
Change -Path to -LiteralPath
muehlings Nov 2, 2022
06e65ed
Update 00-ansible.cmd
muehlings Nov 2, 2022
c1fd633
Update .gitattributes
muehlings Nov 3, 2022
c16b970
Update Linux.yml
muehlings Nov 3, 2022
712d283
Update Windows.yml
muehlings Nov 3, 2022
d21ab95
Update example-linux-inventory.yml
muehlings Nov 3, 2022
a75af5a
Update example-windows-inventory.yml
muehlings Nov 3, 2022
68f9163
Update example-add_hosts.yml
muehlings Nov 3, 2022
aceef84
Force LF line ending on windows files
muehlings Nov 3, 2022
28f160a
Update 00-ansible.cmd
muehlings Nov 3, 2022
083ff31
Trash
robin-checkmk Nov 4, 2022
8aeb082
Delete example-add_hosts.yml
muehlings Nov 7, 2022
5acbf19
Delete example-linux-inventory.yml
muehlings Nov 7, 2022
a28fd9f
Delete example-windows-inventory.yml
muehlings Nov 7, 2022
66dc98a
Fix main.yml after merges.
robin-checkmk Nov 30, 2022
fd894b4
Clean up Jinja spacing in task names.
robin-checkmk Nov 30, 2022
573aafd
Add and change files of agent role
muehlings Oct 14, 2022
5117fe4
Add example playbooks and inventories
muehlings Oct 14, 2022
739a7b2
Remove newline
muehlings Nov 1, 2022
5859281
Change extension
muehlings Nov 1, 2022
eb1957d
Update example-add_hosts.yml
muehlings Nov 1, 2022
041b379
Update 01-winrm-quickconfig.cmd
muehlings Nov 1, 2022
82d1abc
Update Windows.yml
muehlings Nov 2, 2022
01ab008
Update example-linux-inventory.yml
muehlings Nov 3, 2022
d1bbfa8
Update example-windows-inventory.yml
muehlings Nov 3, 2022
0893717
Update example-add_hosts.yml
muehlings Nov 3, 2022
243781e
Update 00-ansible.cmd
muehlings Nov 3, 2022
4aa632a
Delete example-add_hosts.yml
muehlings Nov 7, 2022
b250dde
Delete example-linux-inventory.yml
muehlings Nov 7, 2022
1c45228
Delete example-windows-inventory.yml
muehlings Nov 7, 2022
eeeff51
Fix Jinja2 spacing.
robin-checkmk Jan 16, 2023
73f0b68
Fix too long lines.
robin-checkmk Jan 16, 2023
609e0da
Change -Path to -LiteralPath.
robin-checkmk Jan 16, 2023
71de04a
Add Windows vagrant box.
robin-checkmk Jan 16, 2023
01bc32d
Update Python dependencies.
robin-checkmk Jan 16, 2023
cd2524c
Clean up rebase gotchas.
robin-checkmk Jan 16, 2023
1c2f60f
Merge branch 'feature-agent-windows-support' of github.com:Checkmk/an…
robin-checkmk Jun 23, 2023
a58e7e8
Merge branch 'devel' into feature-agent-windows-support
robin-checkmk Jun 23, 2023
bcd4340
Harmonized Windows Agentrole with Linux
Max-checkmk Jul 25, 2023
1172f7e
pslint
Max-checkmk Jul 25, 2023
c98d3f7
AnsibleLinting
Max-checkmk Jul 25, 2023
35e8b99
AnsibleLint
Max-checkmk Jul 25, 2023
da5bbf1
AnsibleLint_again
Max-checkmk Jul 25, 2023
58dbfcd
Merge branch 'devel' into feature-agent-windows-support
robin-checkmk Jul 27, 2023
7a26200
Fix indentation in Vagrantfile and IP collision.
robin-checkmk Jul 27, 2023
1107737
Improve task title.
robin-checkmk Jul 27, 2023
ca075c0
Fix missing service facts gathering.
robin-checkmk Jul 27, 2023
d60efca
Merge branch 'devel' into feature-agent-windows-support
robin-checkmk Jul 27, 2023
13c8df1
Small improvements and cleanup of PR
Max-checkmk Jul 31, 2023
b01a8e7
Bugfix Vagrantfile.
robin-checkmk Jul 31, 2023
d0449f3
Merge branch 'devel' of github.com:Checkmk/ansible-collection-checkmk…
robin-checkmk Aug 3, 2023
65ef9eb
Bugfix TLS registration conditional.
robin-checkmk Aug 3, 2023
3ede062
Update meta data.
robin-checkmk Aug 3, 2023
b52bec7
Update READMEs.
robin-checkmk Aug 3, 2023
c327763
Add changelog.
robin-checkmk Aug 3, 2023
3e845ef
Harmonize task titles.
robin-checkmk Aug 3, 2023
a5c3f94
Fix spelling.
robin-checkmk Aug 3, 2023
57f3a1a
Add proper retry mechanics.
robin-checkmk Aug 7, 2023
12b360f
Reorganize inventory for better overview and add ansible_shell_type f…
robin-checkmk Aug 10, 2023
7824764
Add verification task for open agent port before discovering services.
robin-checkmk Aug 10, 2023
7efcb76
Merge pull request #406 from Checkmk/feature/roles-resilience-improve…
robin-checkmk Aug 11, 2023
982acd4
Merge pull request #156 from Checkmk/feature-agent-windows-support
robin-checkmk Aug 11, 2023
1bcea19
Fix dummy key for bakery integration tests.
robin-checkmk Aug 14, 2023
7233d35
Split labeling action in two to avoid errors.
robin-checkmk Aug 15, 2023
7927196
Introducing a lookup plugin to get the CMK version of a server
lgetwan Aug 17, 2023
20aac46
Added changelog fragment.
lgetwan Aug 17, 2023
67a5bf6
sanity, part 1.
lgetwan Aug 17, 2023
5194936
QA
lgetwan Aug 17, 2023
8ab2850
sanity, part 2.
lgetwan Aug 17, 2023
0d92542
sanity, part 3 & QA, part 2.
lgetwan Aug 17, 2023
91371b7
Apply Robin's complaints.
lgetwan Aug 18, 2023
86d7c4e
Merge pull request #415 from Checkmk/feature/lookup-version
robin-checkmk Aug 18, 2023
e5a3613
Update labelling.
robin-checkmk Aug 21, 2023
89058d0
Added check for 409 response
Max-checkmk Aug 21, 2023
57f5e8e
Fix linting findings.
robin-checkmk Aug 21, 2023
2fd573d
Bump Checkmk version.
robin-checkmk Aug 21, 2023
10e31ea
Bump collection version.
robin-checkmk Aug 21, 2023
e5b6a5e
Add release summary.
robin-checkmk Aug 21, 2023
0b88146
Separate sleeptimes for single and bulk
Max-checkmk Aug 21, 2023
6bf3935
Add requirement to make molecule happy again.
robin-checkmk Aug 21, 2023
d1c4d5a
Merge pull request #418 from Checkmk/feature/handle-409-response
robin-checkmk Aug 21, 2023
d86d020
Minor changes.
robin-checkmk Aug 22, 2023
47d12aa
Try to fix molecule.
robin-checkmk Aug 22, 2023
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
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.yml linguist-detectable
*.yml linguist-detectable
*.cmd text eol=lf
3 changes: 3 additions & 0 deletions .github/labels-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ module:tag_group:

module:user:
- 'plugins/modules/user.py'

lookup:version:
- 'plugins/modules/lookup/version.py'
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
name: "Labeler"
name: "Label Issues."
on:
issues:
types: [opened, edited]
pull_request_target:
paths:
- 'plugins/**'
- 'roles/**'

permissions:
contents: read
issues: write
pull-requests: write

jobs:

issues:
label:
runs-on: ubuntu-latest
steps:
- name: "Label Issues."
Expand All @@ -25,12 +19,3 @@ jobs:
repo-token: ${{ github.token }}
enable-versioned-regex: 0
sync-labels: 0

pulls:
runs-on: ubuntu-latest
steps:
- name: "Label Pull Requests."
uses: actions/labeler@v4
with:
configuration-path: .github/labels-prs.yml
sync-labels: 0
20 changes: 20 additions & 0 deletions .github/workflows/label-pulls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Label Pull Requests."
on:
pull_request_target:
paths:
- 'plugins/**'
- 'roles/**'

permissions:
contents: read
pull-requests: write

jobs:
label:
runs-on: ubuntu-latest
steps:
- name: "Label Pull Requests."
uses: actions/labeler@v4
with:
configuration-path: .github/labels-prs.yml
sync-labels: 0
2 changes: 1 addition & 1 deletion .github/workflows/molecule-role-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ jobs:
- name: "Run Molecule."
run: |
cd roles/agent/
ln -s ../../requirements.yml requirements.yml
# ln -s ../../requirements.yml requirements.yml
molecule test -s ${{ matrix.checkmk }}
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
2 changes: 1 addition & 1 deletion .github/workflows/molecule-role-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ jobs:
- name: "Run Molecule."
run: |
cd roles/server/
ln -s ../../requirements.yml requirements.yml
# ln -s ../../requirements.yml requirements.yml
molecule test -s ${{ matrix.checkmk }}
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
6 changes: 5 additions & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
/tests/ @robin-checkmk
/roles/ @robin-checkmk
/playbooks/ @robin-checkmk
/plugins/lookup/version.py @lgetwan
/plugins/modules/ @lgetwan
/plugins/module_utils/ @godspeed-you
/plugins/modules/user.py @lgetwan
/plugins/modules/bakery.py @Max-checkmk
/plugins/modules/password.py @Max-checkmk
/plugins/modules/password.py @Max-checkmk
/roles/agent/tasks/Windows.yml @Max-checkmk
/roles/agent/vars/Windows.yml @Max-checkmk
/roles/agent/tasks/Win32NT.yml @Max-checkmk
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ You can also run a subset by mentioning them as follows. See `tests/integration/
ansible-test integration $TEST_CASE --docker

### Molecule
To test our roles, we use [Molecule](https://www.jeffgeerling.com/blog/2018/testing-your-ansible-roles-molecule). It can be installed using the `requirements.txt`in this project or manually. The tests are crafted by the maintainers of this project to reflect real world scenarios a role would be used in. To run the tests, you need to navigate to the role directory and choose a scenario. At the time of writing those are named after the supported Checkmk versions: `2.0.0`and `2.1.0`.
To test our roles, we use [Molecule](https://www.jeffgeerling.com/blog/2018/testing-your-ansible-roles-molecule). It can be installed using the `requirements.txt`in this project or manually. The tests are crafted by the maintainers of this project to reflect real world scenarios a role would be used in. To run the tests, you need to navigate to the role directory and choose a scenario. At the time of writing those are named after the supported Checkmk versions: `2.1.0`and `2.2.0`.

cd roles/server/
molecule test -s 2.0.0
molecule test -s 2.1.0
molecule test -s 2.2.0

### Unit
There are currently no unit tests.
Expand Down
1 change: 1 addition & 0 deletions SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ Collection Version | Checkmk Versions | Ansible Versions | Remarks
2.4.0 | 2.0.0p37, 2.1.0p31, 2.2.0p7 | 2.13, 2.14, 2.15 | None
2.4.1 | 2.0.0p37, 2.1.0p31, 2.2.0p7 | 2.13, 2.14, 2.15 | None
3.0.0 | 2.0.0p38, 2.1.0p32, 2.2.0p7 | 2.13, 2.14, 2.15 | Breaking changes to the following modules: `folder`, `host`, `host_group`, `rule`.
3.1.0 | 2.0.0p38, 2.1.0p32, 2.2.0p7 | 2.13, 2.14, 2.15 | None
16 changes: 16 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,20 @@ Vagrant.configure("2") do |config|
inline: "dnf --quiet check-update ; dnf -y install vim curl wget git"
end

# Windows
config.vm.define "ansidows", autostart: false , primary: false do |srv|
srv.vm.box = "gusztavvargadr/windows-server-2019-standard"
srv.vm.network "private_network", ip: "192.168.56.67"
srv.vm.communicator = "winrm"
srv.vm.hostname = "ansidows"
srv.vm.provider "virtualbox" do |srv|
srv.name = 'ansidows'
srv.memory = 4096
srv.cpus = 2
srv.gui = false
end
srv.vm.provision "shell",
inline: "powershell Set-NetFirewallRule -name 'FPS-ICMP4-ERQ-In*' -Enabled true"
end

end
2 changes: 2 additions & 0 deletions changelogs/fragments/discovery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- Discovery module - Add handling for 409 response.
2 changes: 2 additions & 0 deletions changelogs/fragments/lookup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
major_changes:
- Version lookup plugin - Add Version lookup plugin.
1 change: 1 addition & 0 deletions changelogs/fragments/release_summary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
release_summary: "It is summer and you want to look outside, so we added Windows."
2 changes: 2 additions & 0 deletions changelogs/fragments/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
major_changes:
- Agent role - Add support for Windows.
4 changes: 2 additions & 2 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name: general

# The version of the collection. Must be compatible with semantic versioning

version: 3.0.0
version: 3.1.0

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand All @@ -37,7 +37,7 @@ license_file: LICENSE

# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character
# requirements as 'namespace' and 'name'
tags: [checkmk, monitoring, check_mk, check, discovery, ubuntu, debian, sles, rhel]
tags: [checkmk, monitoring, check_mk, check, discovery, ubuntu, debian, sles, rhel, rocky, rockylinux, oraclelinux, windows]

# Collections that this collection requires to be installed for it to be usable. The key of the dict is the
# collection label 'namespace.name'. The value is a version range
Expand Down
2 changes: 2 additions & 0 deletions playbooks/demo/full.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
- name: "Lookup."
ansible.builtin.import_playbook: lookup.yml
- name: "Hosts and Folders."
ansible.builtin.import_playbook: hosts-and-folders.yml
- name: "Groups."
Expand Down
22 changes: 22 additions & 0 deletions playbooks/demo/lookup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: "Showcase Lookup Plugins."
hosts: test
strategy: linear
gather_facts: false
vars_files:
- ../vars/auth.yml # This vars file provides details about your site

tasks:

- name: "Get Checkmk version."
ansible.builtin.debug:
msg: "Version is {{ version }}"
vars:
version: "{{ lookup('checkmk.general.version',
server_url + '/' + site,
validate_certs=False,
automation_user=automation_user,
automation_secret=automation_secret)
}}"
delegate_to: localhost
run_once: true # noqa run-once[task]
15 changes: 14 additions & 1 deletion playbooks/hosts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,26 @@ test3.tld checkmk_folder_path="/bar"
test4.tld checkmk_folder_path="/"
test5.tld checkmk_folder_path="/foo/bar"

[vagrant]
[linux]
ansibuntu ansible_host=192.168.56.61 checkmk_folder_path="/test"
debsible ansible_host=192.168.56.62 checkmk_folder_path="/foo"
anstream ansible_host=192.168.56.63 checkmk_folder_path="foo/bar"
ansuse ansible_host=192.168.56.64 checkmk_folder_path="/bar"
ansles ansible_host=192.168.56.65 checkmk_folder_path="/bar/foo"
ansoracle ansible_host=192.168.56.66 checkmk_folder_path="/foo"

[windows]
ansidows ansible_host=192.168.56.67 checkmk_folder_path="/"

[windows:vars]
ansible_shell_type = cmd
ansible_winrm_scheme = http
ansible_winrm_transport = basic
ansible_winrm_server_cert_validation = ignore

[vagrant:children]
linux
windows

[vagrant:vars]
ansible_user=vagrant
2 changes: 1 addition & 1 deletion playbooks/usecases/remote-registration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
vars:
# Basic server and authentication information.
# You have to provide the distributed setup yourself.
checkmk_agent_version: "2.1.0p19"
checkmk_agent_version: "2.2.0p7"
checkmk_agent_edition: "cre"
checkmk_agent_user: "cmkadmin"
checkmk_agent_pass: "password"
Expand Down
110 changes: 110 additions & 0 deletions plugins/lookup/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Copyright: (c) 2023, Lars Getwan <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function

__metaclass__ = type

DOCUMENTATION = """
name: version
author: Lars Getwan (@lgetwan)
version_added: "3.1.0"
short_description: Get the version of a Checkmk server
description:
- Returns the version of a Checkmk server as a string, e.g. '2.1.0p31.cre'
options:
_terms:
description: site url
required: True
automation_user:
description: automation user for the REST API access
required: True
automation_secret:
description: automation secret for the REST API access
required: True
validate_certs:
description: Wether or not to validate TLS cerificates
type: boolean
required: False
default: True
"""

EXAMPLES = """
- name: "Show Checkmk version"
debug:
msg: "Server version is {{ version }}"
vars:
version: "{{ lookup('checkmk.general.version',
server_url + '/' + site,
validate_certs=False,
automation_user=automation_user,
automation_secret=automation_secret
)}}"
"""

RETURN = """
_list:
description:
- server Checkmk version
type: list
elements: str
"""

import json
from urllib.error import HTTPError, URLError

from ansible.errors import AnsibleError
from ansible.module_utils.common.text.converters import to_native, to_text
from ansible.module_utils.urls import ConnectionError, SSLValidationError, open_url
from ansible.plugins.lookup import LookupBase


class LookupModule(LookupBase):
def run(self, terms, variables, **kwargs):

self.set_options(var_options=variables, direct=kwargs)
user = self.get_option("automation_user")
secret = self.get_option("automation_secret")
validate_certs = self.get_option("validate_certs")

ret = []
for term in terms:
base_url = term + "/check_mk/api/1.0"
api_endpoint = "/version"
url = base_url + api_endpoint

headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Bearer %s %s" % (user, secret),
}

try:
response = open_url(
url,
data=None,
headers=headers,
method="GET",
validate_certs=validate_certs,
)

except HTTPError as e:
raise AnsibleError(
"Received HTTP error for %s : %s" % (url, to_native(e))
)
except URLError as e:
raise AnsibleError(
"Failed lookup url for %s : %s" % (url, to_native(e))
)
except SSLValidationError as e:
raise AnsibleError(
"Error validating the server's certificate for %s: %s"
% (url, to_native(e))
)
except ConnectionError as e:
raise AnsibleError("Error connecting to %s: %s" % (url, to_native(e)))

checkmkinfo = json.loads(to_text(response.read()))
ret.append(checkmkinfo.get("versions").get("checkmk"))

return ret
15 changes: 14 additions & 1 deletion plugins/modules/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
403: (False, True, "Forbidden: Configuration via WATO is disabled."),
404: (False, True, "Not Found: Host could not be found."),
406: (False, True, "Not Acceptable."),
409: (False, False, "Conflict: A discovery background job is already running"),
415: (False, True, "Unsupported Media Type."),
500: (False, True, "General Server Error."),
}
Expand All @@ -153,7 +154,7 @@
400: (False, True, "Bad Request."),
403: (False, True, "Forbidden: Configuration via WATO is disabled."),
406: (False, True, "Not Acceptable."),
409: (False, True, "Conflict: A bulk discovery job is already active"),
409: (False, False, "Conflict: A bulk discovery job is already active"),
415: (False, True, "Unsupported Media Type."),
500: (False, True, "General Server Error."),
}
Expand Down Expand Up @@ -352,6 +353,18 @@ def run_module():

result = discovery.post()

# In case the API returns 409 (discovery running) we wait and try again.
# This can happen as example in versions where the endpoint doesn't respond with the correct redirect.
while (single_mode and result.http_code == 409) or (
len(module.params.get("hosts", [])) > 0 and result.http_code == 409
):
if single_mode:
time.sleep(1)
else:
time.sleep(10)

result = discovery.post()

# If single_mode and the API returns 302, check the service completion endpoint
# If not single_mode and the API returns 200, check the service completion endpoint
if (single_mode and result.http_code == 302) or (
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ ansible-lint
jinja2
molecule >= 5.0.1
molecule-plugins[docker]
yamllint
yamllint
pywinrm
Loading