From 245a56f38472c2ccaf7465c811c52a548d1dfd45 Mon Sep 17 00:00:00 2001 From: Lars Getwan Date: Wed, 11 Sep 2024 15:11:29 +0200 Subject: [PATCH 01/12] Created Lookup Modules 'site' and 'sites'. --- .github/workflows/ans-int-test-lkp-site.yml | 75 ++++++++ .github/workflows/ans-int-test-lkp-sites.yml | 75 ++++++++ plugins/lookup/site.py | 170 ++++++++++++++++++ plugins/lookup/sites.py | 153 ++++++++++++++++ .../lookup_site/lookup_site/tasks/main.yml | 13 ++ .../lookup_site/lookup_site/tasks/test.yml | 31 ++++ .../lookup_site/lookup_site/vars/main.yml | 11 ++ .../targets/lookup_site/tasks/main.yml | 13 ++ .../targets/lookup_site/tasks/test.yml | 31 ++++ .../targets/lookup_site/vars/main.yml | 11 ++ .../targets/lookup_sites/tasks/main.yml | 13 ++ .../targets/lookup_sites/tasks/test.yml | 29 +++ .../targets/lookup_sites/vars/main.yml | 11 ++ 13 files changed, 636 insertions(+) create mode 100644 .github/workflows/ans-int-test-lkp-site.yml create mode 100644 .github/workflows/ans-int-test-lkp-sites.yml create mode 100644 plugins/lookup/site.py create mode 100644 plugins/lookup/sites.py create mode 100644 tests/integration/targets/lookup_site/lookup_site/tasks/main.yml create mode 100644 tests/integration/targets/lookup_site/lookup_site/tasks/test.yml create mode 100644 tests/integration/targets/lookup_site/lookup_site/vars/main.yml create mode 100644 tests/integration/targets/lookup_site/tasks/main.yml create mode 100644 tests/integration/targets/lookup_site/tasks/test.yml create mode 100644 tests/integration/targets/lookup_site/vars/main.yml create mode 100644 tests/integration/targets/lookup_sites/tasks/main.yml create mode 100644 tests/integration/targets/lookup_sites/tasks/test.yml create mode 100644 tests/integration/targets/lookup_sites/vars/main.yml diff --git a/.github/workflows/ans-int-test-lkp-site.yml b/.github/workflows/ans-int-test-lkp-site.yml new file mode 100644 index 000000000..ecb5979e2 --- /dev/null +++ b/.github/workflows/ans-int-test-lkp-site.yml @@ -0,0 +1,75 @@ +# README: +# - When changing the module name, it needs to be changed in 'env:MODULE_NAME' and in 'on:pull_requests:path'! +# +# Resources: +# - Template for this file: https://github.com/ansible-collections/collection_template/blob/main/.github/workflows/ansible-test.yml +# - About Ansible integration tests: https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html + +env: + NAMESPACE: checkmk + COLLECTION_NAME: general + MODULE_NAME: lookup_site + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +name: Ansible Integration Tests for Site Lookup Module +on: + workflow_dispatch: + pull_request: + branches: + - main + - devel + paths: + - 'plugins/lookup/site.py' + push: + paths: + - 'plugins/lookup/site.py' + +jobs: + + integration: + runs-on: ubuntu-22.04 + name: Ⓐ${{ matrix.ansible }}+py${{ matrix.python }} + strategy: + fail-fast: false + matrix: + ansible: + - stable-2.15 + - stable-2.16 + - stable-2.17 + - devel + python: + - '3.9' + - '3.10' + - '3.11' + - '3.12' + exclude: + # Exclude unsupported sets. + - ansible: stable-2.15 + python: '3.12' + + steps: + - name: Check out code + uses: actions/checkout@v4 + with: + path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install ansible-base (${{ matrix.ansible }}) + run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check + + - name: Provide secrets file + run: echo "${{ secrets.CHECKMK_DOWNLOAD_PW }}" > ./tests/integration/files/.dl-secret + working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} + env: + CHECKMK_DOWNLOAD_PW: ${{ secrets.CHECKMK_DOWNLOAD_PW }} + + - name: Run integration test + run: ansible-test integration ${{env.MODULE_NAME}} -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --docker default + working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} diff --git a/.github/workflows/ans-int-test-lkp-sites.yml b/.github/workflows/ans-int-test-lkp-sites.yml new file mode 100644 index 000000000..94f4df785 --- /dev/null +++ b/.github/workflows/ans-int-test-lkp-sites.yml @@ -0,0 +1,75 @@ +# README: +# - When changing the module name, it needs to be changed in 'env:MODULE_NAME' and in 'on:pull_requests:path'! +# +# Resources: +# - Template for this file: https://github.com/ansible-collections/collection_template/blob/main/.github/workflows/ansible-test.yml +# - About Ansible integration tests: https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html + +env: + NAMESPACE: checkmk + COLLECTION_NAME: general + MODULE_NAME: lookup_sites + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +name: Ansible Integration Tests for Sites Lookup Module +on: + workflow_dispatch: + pull_request: + branches: + - main + - devel + paths: + - 'plugins/lookup/site.py' + push: + paths: + - 'plugins/lookup/site.py' + +jobs: + + integration: + runs-on: ubuntu-22.04 + name: Ⓐ${{ matrix.ansible }}+py${{ matrix.python }} + strategy: + fail-fast: false + matrix: + ansible: + - stable-2.15 + - stable-2.16 + - stable-2.17 + - devel + python: + - '3.9' + - '3.10' + - '3.11' + - '3.12' + exclude: + # Exclude unsupported sets. + - ansible: stable-2.15 + python: '3.12' + + steps: + - name: Check out code + uses: actions/checkout@v4 + with: + path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install ansible-base (${{ matrix.ansible }}) + run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check + + - name: Provide secrets file + run: echo "${{ secrets.CHECKMK_DOWNLOAD_PW }}" > ./tests/integration/files/.dl-secret + working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} + env: + CHECKMK_DOWNLOAD_PW: ${{ secrets.CHECKMK_DOWNLOAD_PW }} + + - name: Run integration test + run: ansible-test integration ${{env.MODULE_NAME}} -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --docker default + working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} diff --git a/plugins/lookup/site.py b/plugins/lookup/site.py new file mode 100644 index 000000000..962000cff --- /dev/null +++ b/plugins/lookup/site.py @@ -0,0 +1,170 @@ +# Copyright: (c) 2023, Lars Getwan +# 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: site + author: Lars Getwan (@lgetwan) + version_added: "5.3.0" + + short_description: Show the configuration of a site + + description: + - Returns the configuration of a distributed monitoring site + + options: + + _terms: + description: site ID + required: True + + server_url: + description: URL of the Checkmk server. + required: True + vars: + - name: ansible_lookup_checkmk_server_url + env: + - name: ANSIBLE_LOOKUP_CHECKMK_SERVER_URL + ini: + - section: checkmk_lookup + key: server_url + + site: + description: Site name for REST API access. + required: True + vars: + - name: ansible_lookup_checkmk_site + env: + - name: ANSIBLE_LOOKUP_CHECKMK_SITE + ini: + - section: checkmk_lookup + key: site + + automation_user: + description: Automation user for the REST API access. + required: True + vars: + - name: ansible_lookup_checkmk_automation_user + env: + - name: ANSIBLE_LOOKUP_CHECKMK_AUTOMATION_USER + ini: + - section: checkmk_lookup + key: automation_user + + automation_secret: + description: Automation secret for the REST API access. + required: True + vars: + - name: ansible_lookup_checkmk_automation_secret + env: + - name: ANSIBLE_LOOKUP_CHECKMK_AUTOMATION_SECRET + ini: + - section: checkmk_lookup + key: automation_secret + + validate_certs: + description: Whether or not to validate TLS certificates. + type: boolean + required: False + default: True + vars: + - name: ansible_lookup_checkmk_validate_certs + env: + - name: ANSIBLE_LOOKUP_CHECKMK_VALIDATE_CERTS + ini: + - section: checkmk_lookup + key: validate_certs + + notes: + - Like all lookups, this runs on the Ansible controller and is unaffected by other keywords such as 'become'. + If you need to use different permissions, you must change the command or run Ansible as another user. + - Alternatively, you can use a shell/command task that runs against localhost and registers the result. + - The directory of the play is used as the current working directory. + - It is B(NOT) possible to assign other variables to the variables mentioned in the C(vars) section! + This is a limitation of Ansible itself. +""" + +EXAMPLES = """ +- name: Get a site with a particular site id + ansible.builtin.debug: + msg: "site: {{ extensions }}" + vars: + extensions: "{{ + lookup('checkmk.general.site', + 'my_remote_site', + server_url=server_url, + site=site, + automation_user=automation_user, + automation_secret=automation_secret, + validate_certs=False + ) + }}" + +- name: "Use variables outside the module call." + ansible.builtin.debug: + msg: "site: {{ extensions }}" + vars: + ansible_lookup_checkmk_server_url: "http://myserver/" + ansible_lookup_checkmk_site: "mysite" + ansible_lookup_checkmk_automation_user: "myuser" + ansible_lookup_checkmk_automation_secret: "mysecret" + ansible_lookup_checkmk_validate_certs: false + attributes: "{{ lookup('checkmk.general.site', 'my_remote_site') }}" +""" + +RETURN = """ + _list: + description: + - The details of a particular site + type: list + elements: str +""" + +import json + +from ansible.errors import AnsibleError +from ansible.plugins.lookup import LookupBase +from ansible_collections.checkmk.general.plugins.module_utils.lookup_api import ( + CheckMKLookupAPI, +) + + +class LookupModule(LookupBase): + def run(self, terms, variables, **kwargs): + self.set_options(var_options=variables, direct=kwargs) + server_url = self.get_option("server_url") + site = self.get_option("site") + user = self.get_option("automation_user") + secret = self.get_option("automation_secret") + validate_certs = self.get_option("validate_certs") + + site_url = server_url + "/" + site + + api = CheckMKLookupAPI( + site_url=site_url, + user=user, + secret=secret, + validate_certs=validate_certs, + ) + + ret = [] + + for term in terms: + response = json.loads(api.get("/objects/site_connection/" + term)) + + if "code" in response: + raise AnsibleError( + "Received error for %s - %s: %s" + % ( + response.get("url", ""), + response.get("code", ""), + response.get("msg", ""), + ) + ) + + ret.append(response.get("extensions", {})) + + return ret diff --git a/plugins/lookup/sites.py b/plugins/lookup/sites.py new file mode 100644 index 000000000..2c51feb54 --- /dev/null +++ b/plugins/lookup/sites.py @@ -0,0 +1,153 @@ +# Copyright: (c) 2023, Lars Getwan +# 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: sites + author: Lars Getwan (@lgetwan) + version_added: "5.3.0" + + short_description: Get a list of all sites + + description: + - Returns a list of all sites and their configuration. + + options: + + server_url: + description: URL of the Checkmk server. + required: True + vars: + - name: ansible_lookup_checkmk_server_url + env: + - name: ANSIBLE_LOOKUP_CHECKMK_SERVER_URL + ini: + - section: checkmk_lookup + key: server_url + + site: + description: Site name for REST API access. + required: True + vars: + - name: ansible_lookup_checkmk_site + env: + - name: ANSIBLE_LOOKUP_CHECKMK_SITE + ini: + - section: checkmk_lookup + key: site + + automation_user: + description: Automation user for the REST API access. + required: True + vars: + - name: ansible_lookup_checkmk_automation_user + env: + - name: ANSIBLE_LOOKUP_CHECKMK_AUTOMATION_USER + ini: + - section: checkmk_lookup + key: automation_user + + automation_secret: + description: Automation secret for the REST API access. + required: True + vars: + - name: ansible_lookup_checkmk_automation_secret + env: + - name: ANSIBLE_LOOKUP_CHECKMK_AUTOMATION_SECRET + ini: + - section: checkmk_lookup + key: automation_secret + + validate_certs: + description: Whether or not to validate TLS certificates. + type: boolean + required: False + default: True + vars: + - name: ansible_lookup_checkmk_validate_certs + env: + - name: ANSIBLE_LOOKUP_CHECKMK_VALIDATE_CERTS + ini: + - section: checkmk_lookup + key: validate_certs + + notes: + - Like all lookups, this runs on the Ansible controller and is unaffected by other keywords such as 'become'. + If you need to use different permissions, you must change the command or run Ansible as another user. + - Alternatively, you can use a shell/command task that runs against localhost and registers the result. + - The directory of the play is used as the current working directory. + - It is B(NOT) possible to assign other variables to the variables mentioned in the C(vars) section! + This is a limitation of Ansible itself. +""" + +EXAMPLES = """ +- name: Get all sites defined in the environment. + ansible.builtin.debug: + msg: "Site: {{ item.extensions }}" + loop: "{{ + lookup('checkmk.general.sites', + server_url=server_url, + site=site, + automation_user=automation_user, + automation_secret=automation_secret, + validate_certs=False + ) + }}" + loop_control: + label: "{{ item.id }}" +""" + +RETURN = """ + _list: + description: + - A list of all sites + type: list + elements: str +""" + +import json + +from ansible.errors import AnsibleError +from ansible.plugins.lookup import LookupBase +from ansible_collections.checkmk.general.plugins.module_utils.lookup_api import ( + CheckMKLookupAPI, +) + + +class LookupModule(LookupBase): + def run(self, terms, variables, **kwargs): + regex_params = {} + self.set_options(var_options=variables, direct=kwargs) + server_url = self.get_option("server_url") + site = self.get_option("site") + user = self.get_option("automation_user") + secret = self.get_option("automation_secret") + validate_certs = self.get_option("validate_certs") + + site_url = server_url + "/" + site + + api = CheckMKLookupAPI( + site_url=site_url, + user=user, + secret=secret, + validate_certs=validate_certs, + ) + + response = json.loads(api.get("/domain-types/site_connection/collections/all")) + + if "code" in response: + raise AnsibleError( + "Received error for %s - %s: %s" + % ( + response.get("url", ""), + response.get("code", ""), + response.get("msg", ""), + ) + ) + + site_list = response.get("value") + + return [site_list] diff --git a/tests/integration/targets/lookup_site/lookup_site/tasks/main.yml b/tests/integration/targets/lookup_site/lookup_site/tasks/main.yml new file mode 100644 index 000000000..bbb3963bc --- /dev/null +++ b/tests/integration/targets/lookup_site/lookup_site/tasks/main.yml @@ -0,0 +1,13 @@ +--- +- name: "Include Global Variables." + ansible.builtin.include_vars: /root/ansible_collections/checkmk/general/tests/integration/files/includes/vars/global.yml + +- name: "Run Preparations." + ansible.builtin.include_tasks: /root/ansible_collections/checkmk/general/tests/integration/files/includes/tasks/prep.yml + +- name: "Testing." + ansible.builtin.include_tasks: test.yml + loop: "{{ test_sites }}" + loop_control: + loop_var: outer_item + when: (download_pass is defined and download_pass | length) or outer_item.edition == "cre" diff --git a/tests/integration/targets/lookup_site/lookup_site/tasks/test.yml b/tests/integration/targets/lookup_site/lookup_site/tasks/test.yml new file mode 100644 index 000000000..086c1f325 --- /dev/null +++ b/tests/integration/targets/lookup_site/lookup_site/tasks/test.yml @@ -0,0 +1,31 @@ +--- +- name: " {{ outer_item.version }} - {{ outer_item.edition | upper }} - Get config of the site." + ansible.builtin.debug: + msg: "Config of site {{ site.id }} is {{ site.extensions }}" + vars: + site: "{{ lookup('checkmk.general.site', + outer_item.site, + server_url=checkmk_var_server_url, + site=outer_item.site, + validate_certs=False, + automation_user=checkmk_var_automation_user, + automation_secret=checkmk_var_automation_secret) + }}[0]" + delegate_to: localhost + run_once: true # noqa run-once[task] + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify local connection." + ansible.builtin.assert: + that: "extensions.status_connection.connection.socket_type == 'local'" + vars: + extensions: "{{ lookup('checkmk.general.site', + outer_item.site, + server_url=checkmk_var_server_url, + site=outer_item.site, + validate_certs=False, + automation_user=checkmk_var_automation_user, + automation_secret=checkmk_var_automation_secret) + }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + diff --git a/tests/integration/targets/lookup_site/lookup_site/vars/main.yml b/tests/integration/targets/lookup_site/lookup_site/vars/main.yml new file mode 100644 index 000000000..d5c692f5c --- /dev/null +++ b/tests/integration/targets/lookup_site/lookup_site/vars/main.yml @@ -0,0 +1,11 @@ +--- +test_sites: + - version: "2.3.0p13" + edition: "cee" + site: "stable_cee" + - version: "2.3.0p13" + edition: "cre" + site: "stable_cre" + - version: "2.2.0p32" + edition: "cre" + site: "old_cre" diff --git a/tests/integration/targets/lookup_site/tasks/main.yml b/tests/integration/targets/lookup_site/tasks/main.yml new file mode 100644 index 000000000..bbb3963bc --- /dev/null +++ b/tests/integration/targets/lookup_site/tasks/main.yml @@ -0,0 +1,13 @@ +--- +- name: "Include Global Variables." + ansible.builtin.include_vars: /root/ansible_collections/checkmk/general/tests/integration/files/includes/vars/global.yml + +- name: "Run Preparations." + ansible.builtin.include_tasks: /root/ansible_collections/checkmk/general/tests/integration/files/includes/tasks/prep.yml + +- name: "Testing." + ansible.builtin.include_tasks: test.yml + loop: "{{ test_sites }}" + loop_control: + loop_var: outer_item + when: (download_pass is defined and download_pass | length) or outer_item.edition == "cre" diff --git a/tests/integration/targets/lookup_site/tasks/test.yml b/tests/integration/targets/lookup_site/tasks/test.yml new file mode 100644 index 000000000..086c1f325 --- /dev/null +++ b/tests/integration/targets/lookup_site/tasks/test.yml @@ -0,0 +1,31 @@ +--- +- name: " {{ outer_item.version }} - {{ outer_item.edition | upper }} - Get config of the site." + ansible.builtin.debug: + msg: "Config of site {{ site.id }} is {{ site.extensions }}" + vars: + site: "{{ lookup('checkmk.general.site', + outer_item.site, + server_url=checkmk_var_server_url, + site=outer_item.site, + validate_certs=False, + automation_user=checkmk_var_automation_user, + automation_secret=checkmk_var_automation_secret) + }}[0]" + delegate_to: localhost + run_once: true # noqa run-once[task] + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify local connection." + ansible.builtin.assert: + that: "extensions.status_connection.connection.socket_type == 'local'" + vars: + extensions: "{{ lookup('checkmk.general.site', + outer_item.site, + server_url=checkmk_var_server_url, + site=outer_item.site, + validate_certs=False, + automation_user=checkmk_var_automation_user, + automation_secret=checkmk_var_automation_secret) + }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + diff --git a/tests/integration/targets/lookup_site/vars/main.yml b/tests/integration/targets/lookup_site/vars/main.yml new file mode 100644 index 000000000..d5c692f5c --- /dev/null +++ b/tests/integration/targets/lookup_site/vars/main.yml @@ -0,0 +1,11 @@ +--- +test_sites: + - version: "2.3.0p13" + edition: "cee" + site: "stable_cee" + - version: "2.3.0p13" + edition: "cre" + site: "stable_cre" + - version: "2.2.0p32" + edition: "cre" + site: "old_cre" diff --git a/tests/integration/targets/lookup_sites/tasks/main.yml b/tests/integration/targets/lookup_sites/tasks/main.yml new file mode 100644 index 000000000..bbb3963bc --- /dev/null +++ b/tests/integration/targets/lookup_sites/tasks/main.yml @@ -0,0 +1,13 @@ +--- +- name: "Include Global Variables." + ansible.builtin.include_vars: /root/ansible_collections/checkmk/general/tests/integration/files/includes/vars/global.yml + +- name: "Run Preparations." + ansible.builtin.include_tasks: /root/ansible_collections/checkmk/general/tests/integration/files/includes/tasks/prep.yml + +- name: "Testing." + ansible.builtin.include_tasks: test.yml + loop: "{{ test_sites }}" + loop_control: + loop_var: outer_item + when: (download_pass is defined and download_pass | length) or outer_item.edition == "cre" diff --git a/tests/integration/targets/lookup_sites/tasks/test.yml b/tests/integration/targets/lookup_sites/tasks/test.yml new file mode 100644 index 000000000..045e00bff --- /dev/null +++ b/tests/integration/targets/lookup_sites/tasks/test.yml @@ -0,0 +1,29 @@ +--- +- name: " {{ outer_item.version }} - {{ outer_item.edition | upper }} - Get config of the site." + ansible.builtin.debug: + msg: "Config of site {{ site.id }} is {{ site.extensions }}" + vars: + site: "{{ lookup('checkmk.general.sites', + server_url=checkmk_var_server_url, + site=outer_item.site, + validate_certs=False, + automation_user=checkmk_var_automation_user, + automation_secret=checkmk_var_automation_secret) + }}[0]" + delegate_to: localhost + run_once: true # noqa run-once[task] + +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify local connection." + ansible.builtin.assert: + that: "extensions.status_connection.connection.socket_type == 'local'" + vars: + extensions: "{{ lookup('checkmk.general.sites', + server_url=checkmk_var_server_url, + site=outer_item.site, + validate_certs=False, + automation_user=checkmk_var_automation_user, + automation_secret=checkmk_var_automation_secret) + }}[0]" + delegate_to: localhost + run_once: true # noqa run-once[task] + diff --git a/tests/integration/targets/lookup_sites/vars/main.yml b/tests/integration/targets/lookup_sites/vars/main.yml new file mode 100644 index 000000000..d5c692f5c --- /dev/null +++ b/tests/integration/targets/lookup_sites/vars/main.yml @@ -0,0 +1,11 @@ +--- +test_sites: + - version: "2.3.0p13" + edition: "cee" + site: "stable_cee" + - version: "2.3.0p13" + edition: "cre" + site: "stable_cre" + - version: "2.2.0p32" + edition: "cre" + site: "old_cre" From b97dd9e942df1a474240291d838296c000297b8b Mon Sep 17 00:00:00 2001 From: Lars Getwan Date: Wed, 11 Sep 2024 15:23:25 +0200 Subject: [PATCH 02/12] Debugging --- .../lookup_site/lookup_site/tasks/main.yml | 13 -------- .../lookup_site/lookup_site/tasks/test.yml | 31 ------------------- .../lookup_site/lookup_site/vars/main.yml | 11 ------- .../targets/lookup_site/tasks/test.yml | 5 ++- 4 files changed, 2 insertions(+), 58 deletions(-) delete mode 100644 tests/integration/targets/lookup_site/lookup_site/tasks/main.yml delete mode 100644 tests/integration/targets/lookup_site/lookup_site/tasks/test.yml delete mode 100644 tests/integration/targets/lookup_site/lookup_site/vars/main.yml diff --git a/tests/integration/targets/lookup_site/lookup_site/tasks/main.yml b/tests/integration/targets/lookup_site/lookup_site/tasks/main.yml deleted file mode 100644 index bbb3963bc..000000000 --- a/tests/integration/targets/lookup_site/lookup_site/tasks/main.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -- name: "Include Global Variables." - ansible.builtin.include_vars: /root/ansible_collections/checkmk/general/tests/integration/files/includes/vars/global.yml - -- name: "Run Preparations." - ansible.builtin.include_tasks: /root/ansible_collections/checkmk/general/tests/integration/files/includes/tasks/prep.yml - -- name: "Testing." - ansible.builtin.include_tasks: test.yml - loop: "{{ test_sites }}" - loop_control: - loop_var: outer_item - when: (download_pass is defined and download_pass | length) or outer_item.edition == "cre" diff --git a/tests/integration/targets/lookup_site/lookup_site/tasks/test.yml b/tests/integration/targets/lookup_site/lookup_site/tasks/test.yml deleted file mode 100644 index 086c1f325..000000000 --- a/tests/integration/targets/lookup_site/lookup_site/tasks/test.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- -- name: " {{ outer_item.version }} - {{ outer_item.edition | upper }} - Get config of the site." - ansible.builtin.debug: - msg: "Config of site {{ site.id }} is {{ site.extensions }}" - vars: - site: "{{ lookup('checkmk.general.site', - outer_item.site, - server_url=checkmk_var_server_url, - site=outer_item.site, - validate_certs=False, - automation_user=checkmk_var_automation_user, - automation_secret=checkmk_var_automation_secret) - }}[0]" - delegate_to: localhost - run_once: true # noqa run-once[task] - -- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify local connection." - ansible.builtin.assert: - that: "extensions.status_connection.connection.socket_type == 'local'" - vars: - extensions: "{{ lookup('checkmk.general.site', - outer_item.site, - server_url=checkmk_var_server_url, - site=outer_item.site, - validate_certs=False, - automation_user=checkmk_var_automation_user, - automation_secret=checkmk_var_automation_secret) - }}" - delegate_to: localhost - run_once: true # noqa run-once[task] - diff --git a/tests/integration/targets/lookup_site/lookup_site/vars/main.yml b/tests/integration/targets/lookup_site/lookup_site/vars/main.yml deleted file mode 100644 index d5c692f5c..000000000 --- a/tests/integration/targets/lookup_site/lookup_site/vars/main.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -test_sites: - - version: "2.3.0p13" - edition: "cee" - site: "stable_cee" - - version: "2.3.0p13" - edition: "cre" - site: "stable_cre" - - version: "2.2.0p32" - edition: "cre" - site: "old_cre" diff --git a/tests/integration/targets/lookup_site/tasks/test.yml b/tests/integration/targets/lookup_site/tasks/test.yml index 086c1f325..ae871882f 100644 --- a/tests/integration/targets/lookup_site/tasks/test.yml +++ b/tests/integration/targets/lookup_site/tasks/test.yml @@ -1,9 +1,9 @@ --- - name: " {{ outer_item.version }} - {{ outer_item.edition | upper }} - Get config of the site." ansible.builtin.debug: - msg: "Config of site {{ site.id }} is {{ site.extensions }}" + msg: "Config of site {{ extensions.basic_settings.site_id }} is {{ extensions }}" vars: - site: "{{ lookup('checkmk.general.site', + extensions: "{{ lookup('checkmk.general.site', outer_item.site, server_url=checkmk_var_server_url, site=outer_item.site, @@ -28,4 +28,3 @@ }}" delegate_to: localhost run_once: true # noqa run-once[task] - From d7de286a6823ca2daaf5b57bf21425ee1f65e346 Mon Sep 17 00:00:00 2001 From: Lars Getwan Date: Wed, 11 Sep 2024 15:31:43 +0200 Subject: [PATCH 03/12] Debugging --- tests/integration/targets/lookup_site/tasks/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/integration/targets/lookup_site/tasks/test.yml b/tests/integration/targets/lookup_site/tasks/test.yml index ae871882f..1bc1f8e4e 100644 --- a/tests/integration/targets/lookup_site/tasks/test.yml +++ b/tests/integration/targets/lookup_site/tasks/test.yml @@ -1,7 +1,8 @@ --- - name: " {{ outer_item.version }} - {{ outer_item.edition | upper }} - Get config of the site." ansible.builtin.debug: - msg: "Config of site {{ extensions.basic_settings.site_id }} is {{ extensions }}" + #msg: "Config of site {{ extensions.basic_settings.site_id }} is {{ extensions }}" + msg: "Config of site is {{ extensions }}" vars: extensions: "{{ lookup('checkmk.general.site', outer_item.site, From c5742dabcdf91411fb3957bff7791191e47fdcb0 Mon Sep 17 00:00:00 2001 From: Lars Getwan Date: Wed, 11 Sep 2024 15:41:13 +0200 Subject: [PATCH 04/12] Debugging --- tests/integration/targets/lookup_sites/tasks/test.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/integration/targets/lookup_sites/tasks/test.yml b/tests/integration/targets/lookup_sites/tasks/test.yml index 045e00bff..b4a29bccb 100644 --- a/tests/integration/targets/lookup_sites/tasks/test.yml +++ b/tests/integration/targets/lookup_sites/tasks/test.yml @@ -1,9 +1,9 @@ --- - name: " {{ outer_item.version }} - {{ outer_item.edition | upper }} - Get config of the site." ansible.builtin.debug: - msg: "Config of site {{ site.id }} is {{ site.extensions }}" + msg: "Config of site {{ extensions.basic_settings.site_id }} is {{ extensions }}" vars: - site: "{{ lookup('checkmk.general.sites', + extensions: "{{ lookup('checkmk.general.sites', server_url=checkmk_var_server_url, site=outer_item.site, validate_certs=False, @@ -26,4 +26,3 @@ }}[0]" delegate_to: localhost run_once: true # noqa run-once[task] - From 246a66a116eda0b83e3d47c13e6ffdead97325ed Mon Sep 17 00:00:00 2001 From: Lars Getwan Date: Wed, 11 Sep 2024 16:04:55 +0200 Subject: [PATCH 05/12] Debugging --- tests/integration/targets/lookup_site/tasks/test.yml | 2 +- tests/integration/targets/lookup_sites/tasks/test.yml | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/integration/targets/lookup_site/tasks/test.yml b/tests/integration/targets/lookup_site/tasks/test.yml index 1bc1f8e4e..7abea3575 100644 --- a/tests/integration/targets/lookup_site/tasks/test.yml +++ b/tests/integration/targets/lookup_site/tasks/test.yml @@ -2,7 +2,7 @@ - name: " {{ outer_item.version }} - {{ outer_item.edition | upper }} - Get config of the site." ansible.builtin.debug: #msg: "Config of site {{ extensions.basic_settings.site_id }} is {{ extensions }}" - msg: "Config of site is {{ extensions }}" + msg: "Config of site {{ extensions.basic_settings.site_id }} is {{ extensions }}" vars: extensions: "{{ lookup('checkmk.general.site', outer_item.site, diff --git a/tests/integration/targets/lookup_sites/tasks/test.yml b/tests/integration/targets/lookup_sites/tasks/test.yml index b4a29bccb..4f15a07c2 100644 --- a/tests/integration/targets/lookup_sites/tasks/test.yml +++ b/tests/integration/targets/lookup_sites/tasks/test.yml @@ -1,15 +1,16 @@ --- - name: " {{ outer_item.version }} - {{ outer_item.edition | upper }} - Get config of the site." ansible.builtin.debug: - msg: "Config of site {{ extensions.basic_settings.site_id }} is {{ extensions }}" - vars: - extensions: "{{ lookup('checkmk.general.sites', + msg: "Config of site {{ item.id }} is {{ item.extensions }}" + loop: "{{ lookup('checkmk.general.sites', server_url=checkmk_var_server_url, site=outer_item.site, validate_certs=False, automation_user=checkmk_var_automation_user, automation_secret=checkmk_var_automation_secret) - }}[0]" + }}" + loop_control: + label: "{{ item.id }}" delegate_to: localhost run_once: true # noqa run-once[task] From 389fab711f6f3f6aa0934b7dc867dca8b3528d23 Mon Sep 17 00:00:00 2001 From: Lars Getwan Date: Fri, 13 Sep 2024 15:10:24 +0200 Subject: [PATCH 06/12] Debugging --- tests/integration/targets/lookup_site/tasks/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/lookup_site/tasks/test.yml b/tests/integration/targets/lookup_site/tasks/test.yml index 7abea3575..d0eb7005c 100644 --- a/tests/integration/targets/lookup_site/tasks/test.yml +++ b/tests/integration/targets/lookup_site/tasks/test.yml @@ -26,6 +26,6 @@ validate_certs=False, automation_user=checkmk_var_automation_user, automation_secret=checkmk_var_automation_secret) - }}" + }}[0]" delegate_to: localhost run_once: true # noqa run-once[task] From 7cff0d6594607f6a96f45727b831f30573e5f989 Mon Sep 17 00:00:00 2001 From: Lars Getwan Date: Fri, 13 Sep 2024 15:24:29 +0200 Subject: [PATCH 07/12] Debugging --- .../integration/targets/lookup_site/tasks/test.yml | 2 +- .../targets/lookup_sites/tasks/test.yml | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/integration/targets/lookup_site/tasks/test.yml b/tests/integration/targets/lookup_site/tasks/test.yml index d0eb7005c..ca80c35f2 100644 --- a/tests/integration/targets/lookup_site/tasks/test.yml +++ b/tests/integration/targets/lookup_site/tasks/test.yml @@ -2,7 +2,7 @@ - name: " {{ outer_item.version }} - {{ outer_item.edition | upper }} - Get config of the site." ansible.builtin.debug: #msg: "Config of site {{ extensions.basic_settings.site_id }} is {{ extensions }}" - msg: "Config of site {{ extensions.basic_settings.site_id }} is {{ extensions }}" + msg: "Config of site {{ extensions }} is {{ extensions }}" vars: extensions: "{{ lookup('checkmk.general.site', outer_item.site, diff --git a/tests/integration/targets/lookup_sites/tasks/test.yml b/tests/integration/targets/lookup_sites/tasks/test.yml index 4f15a07c2..374d4c111 100644 --- a/tests/integration/targets/lookup_sites/tasks/test.yml +++ b/tests/integration/targets/lookup_sites/tasks/test.yml @@ -14,6 +14,20 @@ delegate_to: localhost run_once: true # noqa run-once[task] +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify local connection." + ansible.builtin.debug: + msg: "{{ extensions }}" + vars: + extensions: "{{ lookup('checkmk.general.sites', + server_url=checkmk_var_server_url, + site=outer_item.site, + validate_certs=False, + automation_user=checkmk_var_automation_user, + automation_secret=checkmk_var_automation_secret) + }}[0]" + delegate_to: localhost + run_once: true # noqa run-once[task] + - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify local connection." ansible.builtin.assert: that: "extensions.status_connection.connection.socket_type == 'local'" From 6a1d16bd4946018e8bec24b4fa5db380fe2dfac3 Mon Sep 17 00:00:00 2001 From: Lars Getwan Date: Fri, 13 Sep 2024 16:10:10 +0200 Subject: [PATCH 08/12] Oba jetze! --- .../targets/lookup_site/tasks/test.yml | 8 ++++---- .../targets/lookup_sites/tasks/test.yml | 18 ++---------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/tests/integration/targets/lookup_site/tasks/test.yml b/tests/integration/targets/lookup_site/tasks/test.yml index ca80c35f2..8cca89711 100644 --- a/tests/integration/targets/lookup_site/tasks/test.yml +++ b/tests/integration/targets/lookup_site/tasks/test.yml @@ -2,7 +2,7 @@ - name: " {{ outer_item.version }} - {{ outer_item.edition | upper }} - Get config of the site." ansible.builtin.debug: #msg: "Config of site {{ extensions.basic_settings.site_id }} is {{ extensions }}" - msg: "Config of site {{ extensions }} is {{ extensions }}" + msg: "Config of site {{ extensions }}" vars: extensions: "{{ lookup('checkmk.general.site', outer_item.site, @@ -11,13 +11,13 @@ validate_certs=False, automation_user=checkmk_var_automation_user, automation_secret=checkmk_var_automation_secret) - }}[0]" + }}" delegate_to: localhost run_once: true # noqa run-once[task] - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify local connection." ansible.builtin.assert: - that: "extensions.status_connection.connection.socket_type == 'local'" + that: "extensions[0].status_connection.connection.socket_type == 'local'" vars: extensions: "{{ lookup('checkmk.general.site', outer_item.site, @@ -26,6 +26,6 @@ validate_certs=False, automation_user=checkmk_var_automation_user, automation_secret=checkmk_var_automation_secret) - }}[0]" + }}" delegate_to: localhost run_once: true # noqa run-once[task] diff --git a/tests/integration/targets/lookup_sites/tasks/test.yml b/tests/integration/targets/lookup_sites/tasks/test.yml index 374d4c111..3aaa94826 100644 --- a/tests/integration/targets/lookup_sites/tasks/test.yml +++ b/tests/integration/targets/lookup_sites/tasks/test.yml @@ -14,23 +14,9 @@ delegate_to: localhost run_once: true # noqa run-once[task] -- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify local connection." - ansible.builtin.debug: - msg: "{{ extensions }}" - vars: - extensions: "{{ lookup('checkmk.general.sites', - server_url=checkmk_var_server_url, - site=outer_item.site, - validate_certs=False, - automation_user=checkmk_var_automation_user, - automation_secret=checkmk_var_automation_secret) - }}[0]" - delegate_to: localhost - run_once: true # noqa run-once[task] - - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify local connection." ansible.builtin.assert: - that: "extensions.status_connection.connection.socket_type == 'local'" + that: "extensions[0].status_connection.connection.socket_type == 'local'" vars: extensions: "{{ lookup('checkmk.general.sites', server_url=checkmk_var_server_url, @@ -38,6 +24,6 @@ validate_certs=False, automation_user=checkmk_var_automation_user, automation_secret=checkmk_var_automation_secret) - }}[0]" + }}" delegate_to: localhost run_once: true # noqa run-once[task] From 9e937a08dedc193b4ccc63703f55373e5283849e Mon Sep 17 00:00:00 2001 From: Lars Getwan Date: Fri, 13 Sep 2024 16:30:02 +0200 Subject: [PATCH 09/12] sigh... --- .../targets/lookup_site/tasks/test.yml | 4 ++-- .../targets/lookup_sites/tasks/test.yml | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/integration/targets/lookup_site/tasks/test.yml b/tests/integration/targets/lookup_site/tasks/test.yml index 8cca89711..3cdc18eaf 100644 --- a/tests/integration/targets/lookup_site/tasks/test.yml +++ b/tests/integration/targets/lookup_site/tasks/test.yml @@ -2,7 +2,7 @@ - name: " {{ outer_item.version }} - {{ outer_item.edition | upper }} - Get config of the site." ansible.builtin.debug: #msg: "Config of site {{ extensions.basic_settings.site_id }} is {{ extensions }}" - msg: "Config of site {{ extensions }}" + msg: "Config of site {{ extensions.basic_settings.site_id }}: {{ extensions }}" vars: extensions: "{{ lookup('checkmk.general.site', outer_item.site, @@ -17,7 +17,7 @@ - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify local connection." ansible.builtin.assert: - that: "extensions[0].status_connection.connection.socket_type == 'local'" + that: "extensions.status_connection.connection.socket_type == 'local'" vars: extensions: "{{ lookup('checkmk.general.site', outer_item.site, diff --git a/tests/integration/targets/lookup_sites/tasks/test.yml b/tests/integration/targets/lookup_sites/tasks/test.yml index 3aaa94826..785d038bb 100644 --- a/tests/integration/targets/lookup_sites/tasks/test.yml +++ b/tests/integration/targets/lookup_sites/tasks/test.yml @@ -14,9 +14,23 @@ delegate_to: localhost run_once: true # noqa run-once[task] +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify local connection." + ansible.builtin.debug: + msg: "{{ extensions }}" + vars: + extensions: "{{ lookup('checkmk.general.sites', + server_url=checkmk_var_server_url, + site=outer_item.site, + validate_certs=False, + automation_user=checkmk_var_automation_user, + automation_secret=checkmk_var_automation_secret) + }}" + delegate_to: localhost + run_once: true # noqa run-once[task] + - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify local connection." ansible.builtin.assert: - that: "extensions[0].status_connection.connection.socket_type == 'local'" + that: "extensions.status_connection.connection.socket_type == 'local'" vars: extensions: "{{ lookup('checkmk.general.sites', server_url=checkmk_var_server_url, From d30cb1dafeb149776e80124139f7a17d31567c25 Mon Sep 17 00:00:00 2001 From: Lars Getwan Date: Fri, 13 Sep 2024 16:40:06 +0200 Subject: [PATCH 10/12] Ja, sakra! --- tests/integration/targets/lookup_sites/tasks/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/targets/lookup_sites/tasks/test.yml b/tests/integration/targets/lookup_sites/tasks/test.yml index 785d038bb..296cbca8f 100644 --- a/tests/integration/targets/lookup_sites/tasks/test.yml +++ b/tests/integration/targets/lookup_sites/tasks/test.yml @@ -30,9 +30,9 @@ - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify local connection." ansible.builtin.assert: - that: "extensions.status_connection.connection.socket_type == 'local'" + that: "sites[0].extensions.status_connection.connection.socket_type == 'local'" vars: - extensions: "{{ lookup('checkmk.general.sites', + sites: "{{ lookup('checkmk.general.sites', server_url=checkmk_var_server_url, site=outer_item.site, validate_certs=False, From ddeb5132639a4b4cf25736d8f33bf260cfba9ca0 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 24 Sep 2024 10:57:34 +0200 Subject: [PATCH 11/12] Align file extension with other workflows. --- .../{ans-int-test-lkp-site.yml => ans-int-test-lkp-site.yaml} | 0 .../{ans-int-test-lkp-sites.yml => ans-int-test-lkp-sites.yaml} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{ans-int-test-lkp-site.yml => ans-int-test-lkp-site.yaml} (100%) rename .github/workflows/{ans-int-test-lkp-sites.yml => ans-int-test-lkp-sites.yaml} (100%) diff --git a/.github/workflows/ans-int-test-lkp-site.yml b/.github/workflows/ans-int-test-lkp-site.yaml similarity index 100% rename from .github/workflows/ans-int-test-lkp-site.yml rename to .github/workflows/ans-int-test-lkp-site.yaml diff --git a/.github/workflows/ans-int-test-lkp-sites.yml b/.github/workflows/ans-int-test-lkp-sites.yaml similarity index 100% rename from .github/workflows/ans-int-test-lkp-sites.yml rename to .github/workflows/ans-int-test-lkp-sites.yaml From ec3c3907a6ad907db03c21460415801b368689a0 Mon Sep 17 00:00:00 2001 From: Robin Gierse Date: Tue, 24 Sep 2024 13:16:13 +0200 Subject: [PATCH 12/12] Add modules to README. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 891e52658..c438d4ed2 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ Name | Description | Tests [checkmk.general.rules](https://github.com/Checkmk/ansible-collection-checkmk.general/blob/main/plugins/lookup/rules.py)|Look up all rules.|[![Integration Tests for Rules Lookup Module](https://github.com/Checkmk/ansible-collection-checkmk.general/actions/workflows/ans-int-test-lkp-rules.yaml/badge.svg)](https://github.com/Checkmk/ansible-collection-checkmk.general/actions/workflows/ans-int-test-lkp-rules.yaml) [checkmk.general.ruleset](https://github.com/Checkmk/ansible-collection-checkmk.general/blob/main/plugins/lookup/ruleset.py)|Look up ruleset attributes.|[![Integration Tests for Ruleset Lookup Module](https://github.com/Checkmk/ansible-collection-checkmk.general/actions/workflows/ans-int-test-lkp-rulesets.yaml/badge.svg)](https://github.com/Checkmk/ansible-collection-checkmk.general/actions/workflows/ans-int-test-lkp-rulesets.yaml) [checkmk.general.rulesets](https://github.com/Checkmk/ansible-collection-checkmk.general/blob/main/plugins/lookup/rulesets.py)|Look up all rulesets.|[![Integration Tests for Rulesets Lookup Module](https://github.com/Checkmk/ansible-collection-checkmk.general/actions/workflows/ans-int-test-lkp-rulesets.yaml/badge.svg)](https://github.com/Checkmk/ansible-collection-checkmk.general/actions/workflows/ans-int-test-lkp-rulesets.yaml) +[checkmk.general.site](https://github.com/Checkmk/ansible-collection-checkmk.general/blob/main/plugins/lookup/site.py)|Look up site attributes.|[![Integration Tests for Site Lookup Module](https://github.com/Checkmk/ansible-collection-checkmk.general/actions/workflows/ans-int-test-lkp-site.yaml/badge.svg)](https://github.com/Checkmk/ansible-collection-checkmk.general/actions/workflows/ans-int-test-lkp-site.yaml) +[checkmk.general.sites](https://github.com/Checkmk/ansible-collection-checkmk.general/blob/main/plugins/lookup/sites.py)|Look up all sites.|[![Integration Tests for Sites Lookup Module](https://github.com/Checkmk/ansible-collection-checkmk.general/actions/workflows/ans-int-test-lkp-sites.yaml/badge.svg)](https://github.com/Checkmk/ansible-collection-checkmk.general/actions/workflows/ans-int-test-lkp-sites.yaml) [checkmk.general.version](https://github.com/Checkmk/ansible-collection-checkmk.general/blob/main/plugins/lookup/version.py)|Look up version and edition information.|[![Integration Tests for Version Lookup Module](https://github.com/Checkmk/ansible-collection-checkmk.general/actions/workflows/ans-int-test-lkp-version.yaml/badge.svg)](https://github.com/Checkmk/ansible-collection-checkmk.general/actions/workflows/ans-int-test-lkp-version.yaml) ### Modules