diff --git a/Makefile b/Makefile index 38ad780ff..128a0631f 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,9 @@ COLLECTION_ROOT="/home/vagrant/ansible_collections/checkmk/general" CONTAINER_BUILD_ROOT="$(COLLECTION_ROOT)/tests/container" CONTAINER_NAME="ansible-checkmk-test" +#https://stackoverflow.com/questions/3931741/why-does-make-think-the-target-is-up-to-date +.PHONY: clean + help: @echo "setup - Run all setup target at once." @echo "" @@ -19,12 +22,16 @@ help: @echo "" @echo "vbox - Copy the correct Vagrantfile for use with VirtualBox." @echo "" - @echo "vm - Create a virtual development environment." - @echo "molecule - Create a virtual environment for molecule tests." - @echo "vms - Create a virtual environment with all boxes (exept for the development ones and ansidows)." - @echo "vms-debian - Create a virtual environment with all Debian family OSes." - @echo "vms-redhat - Create a virtual environment with all RedHat family OSes." - @echo "vms-suse - Create a virtual environment with all Suse family OSes." + @echo "setup-vagrant - Install and enable Vagrant." + @echo "" + @echo "venv - Install Python Virtual Environment. You need to activate it yourself though!" + @echo "" + @echo "vm - Create a virtual development environment." + @echo "molecule - Create a virtual environment for molecule tests." + @echo "vms - Create a virtual environment with all boxes (exept for the development ones and ansidows)." + @echo "vms-debian - Create a virtual environment with all Debian family OSes." + @echo "vms-redhat - Create a virtual environment with all RedHat family OSes." + @echo "vms-suse - Create a virtual environment with all Suse family OSes." @echo "" @echo "container - Create a customized container image for testing." @echo "" @@ -61,6 +68,7 @@ setup-python: @sudo apt-get -y update --quiet @sudo apt-get -y install -y \ python3-pip \ + python3-venv \ ca-certificates \ curl \ gnupg \ @@ -98,6 +106,28 @@ vbox: setup-vbox: vbox +setup-vagrant: + @sudo apt update -y + @sudo apt install -y \ + apt-transport-https \ + ca-certificates \ + wget \ + software-properties-common + @wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg + @echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $$(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list + @sudo apt update -y + @sudo apt -y install vagrant + @sudo usermod -aG libvirt $(USER) + @vagrant plugin install vagrant-libvirt + +venv: + @python3 -m venv venv + @echo + @echo "Run the following command to actually activate the venv!" + @echo ". venv/bin/activate" + @echo + @(. venv/bin/activate && python3 -m pip install pip --upgrade && python3 -m pip install -r requirements.txt) + clean: clean-vm clean-vm: diff --git a/README.md b/README.md index 4d2772925..e2e29867c 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,16 @@ See [CONTRIBUTING](CONTRIBUTING.md). See [CHANGELOG.rst](CHANGELOG.rst). +## Versioning + +This collection uses [Semantic Versioning](https://semver.org/) for releases. From the official homepage: + + Given a version number MAJOR.MINOR.PATCH, increment the: + + MAJOR version when you make incompatible API changes + MINOR version when you add functionality in a backward compatible manner + PATCH version when you make backward compatible bug fixes + ## Roadmap This is merely a collection of possible additions to the collection. diff --git a/SUPPORT.md b/SUPPORT.md index d4019f2ca..bd739237c 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -52,3 +52,4 @@ Collection Version | Checkmk Versions | Ansible Versions | Remarks 4.3.0 | 2.0.0p39, 2.1.0p39, 2.2.0p22 | 2.14, 2.15, 2.16 | None 4.3.1 | 2.0.0p39, 2.1.0p39, 2.2.0p22 | 2.14, 2.15, 2.16 | None 4.4.0 | 2.0.0p39, 2.1.0p41, 2.2.0p24 | 2.14, 2.15, 2.16 | None +4.4.1 | 2.0.0p39, 2.1.0p41, 2.2.0p24 | 2.14, 2.15, 2.16 | None diff --git a/Vagrantfile.kvm b/Vagrantfile.kvm index 75b1fb7f2..cbddbc8ef 100644 --- a/Vagrantfile.kvm +++ b/Vagrantfile.kvm @@ -23,7 +23,6 @@ Vagrant.configure("2") do |config| libvirt.memory = 8096 libvirt.cpus = 4 libvirt.title = 'collection' - libvirt.keymap = "de" libvirt.memorybacking :access, :mode => 'shared' libvirt.memorybacking :source, :type => 'memfd' end diff --git a/changelogs/fragments/fix_host_initial_folder.yml b/changelogs/fragments/fix_host_initial_folder.yml new file mode 100644 index 000000000..62dcdba2e --- /dev/null +++ b/changelogs/fragments/fix_host_initial_folder.yml @@ -0,0 +1,2 @@ +bugfixes: + - Host module - Fix hosts always being created in the main directory. diff --git a/changelogs/fragments/meta.yml b/changelogs/fragments/meta.yml new file mode 100644 index 000000000..e55a4bd72 --- /dev/null +++ b/changelogs/fragments/meta.yml @@ -0,0 +1,3 @@ +minor_changes: + - Add 'ansible.utils' collection as an explicitely dependency. + We already had this dependency, but are now declaring it explicitely. diff --git a/changelogs/fragments/release_summary.yml b/changelogs/fragments/release_summary.yml new file mode 100644 index 000000000..b345fa2b5 --- /dev/null +++ b/changelogs/fragments/release_summary.yml @@ -0,0 +1 @@ +release_summary: "Bugfix Release." diff --git a/galaxy.yml b/galaxy.yml index 0a06a45bb..4341748db 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -10,7 +10,7 @@ name: general # The version of the collection. Must be compatible with semantic versioning -version: 4.4.0 +version: 4.4.1 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md @@ -47,6 +47,7 @@ tags: [checkmk, monitoring, check_mk, check, discovery, ubuntu, debian, sles, rh dependencies: "community.general": ">=5.0.0" "ansible.posix": ">=1.4.0" + "ansible.utils": ">=1.0.1" # The URL of the originating SCM repository repository: https://github.com/Checkmk/ansible-collection-checkmk.general diff --git a/plugins/modules/host.py b/plugins/modules/host.py index a29f94b30..627880d46 100644 --- a/plugins/modules/host.py +++ b/plugins/modules/host.py @@ -320,12 +320,7 @@ def __init__(self, module): # Get the current host from the API and set some parameters self._get_current() - if self.state == "present": - if ( - self.params.get("folder") - and self.current["folder"] != self.params["folder"] - ): - self.desired["folder"] = self.params["folder"] + self.desired["folder"] = self.params["folder"] if self.params.get("nodes"): self.desired["nodes"] = self.params.get("nodes") @@ -423,7 +418,7 @@ def _build_modify_cluster_endpoint(self): return HostEndpoints.modify_cluster % self.desired["host_name"] def _detect_changes_folder(self): - current_folder = self.current.get("folder") + current_folder = self.current.get("folder", "/") desired_folder = self.desired.get("folder") changes = [] diff --git a/tests/integration/targets/host/tasks/test.yml b/tests/integration/targets/host/tasks/test.yml index 1bf6ec525..789ef60db 100644 --- a/tests/integration/targets/host/tasks/test.yml +++ b/tests/integration/targets/host/tasks/test.yml @@ -19,7 +19,7 @@ automation_user: "{{ checkmk_var_automation_user }}" automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ item.name }}" - folder: "{{ item.folder }}" + folder: "{{ item.folder | default(omit) }}" attributes: site: "{{ outer_item.site }}" ipaddress: 127.0.0.1 @@ -40,6 +40,22 @@ delegate_to: localhost run_once: true # noqa run-once[task] +- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Verify host folder." + ansible.builtin.assert: + that: "(item.folder | default('/')) == extensions.folder" + vars: + extensions: "{{ lookup('checkmk.general.host', + item.name, + 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] + loop: "{{ checkmk_hosts }}" + - name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Delete hosts." host: server_url: "{{ checkmk_var_server_url }}" @@ -47,7 +63,7 @@ automation_user: "{{ checkmk_var_automation_user }}" automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ item.name }}" - folder: "{{ item.folder }}" + folder: "{{ item.folder | default(omit) }}" state: "absent" delegate_to: localhost run_once: true # noqa run-once[task] @@ -134,7 +150,7 @@ automation_user: "{{ checkmk_var_automation_user }}" automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ item.name }}" - folder: "{{ item.folder }}" + folder: "{{ item.folder | default(omit) }}" state: "absent" delegate_to: localhost run_once: true # noqa run-once[task] @@ -160,7 +176,7 @@ automation_user: "{{ checkmk_var_automation_user }}" automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ item.name }}" - folder: "{{ item.folder }}" + folder: "{{ item.folder | default(omit) }}" attributes: site: "{{ outer_item.site }}" ipaddress: 127.0.0.1 @@ -188,7 +204,7 @@ automation_user: "{{ checkmk_var_automation_user }}" automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ item.name }}" - folder: "{{ item.folder }}" + folder: "{{ item.folder | default(omit) }}" nodes: "{{ item.nodes }}" attributes: site: "{{ outer_item.site }}" @@ -217,7 +233,7 @@ automation_user: "{{ checkmk_var_automation_user }}" automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ item.name }}" - folder: "{{ item.folder }}" + folder: "{{ item.folder | default(omit) }}" nodes: "{{ item.nodes }}" attributes: site: "{{ outer_item.site }}" @@ -234,7 +250,7 @@ automation_user: "{{ checkmk_var_automation_user }}" automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ first.name }}" - folder: "{{ first.folder }}" + folder: "{{ first.folder | default(omit) }}" nodes: "{{ second.nodes }}" attributes: site: "{{ outer_item.site }}" @@ -265,7 +281,7 @@ automation_user: "{{ checkmk_var_automation_user }}" automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ first.name }}" - folder: "{{ first.folder }}" + folder: "{{ first.folder | default(omit) }}" nodes: "{{ second.nodes }}" attributes: site: "{{ outer_item.site }}" @@ -284,7 +300,7 @@ automation_user: "{{ checkmk_var_automation_user }}" automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ item.name }}" - folder: "{{ item.folder }}" + folder: "{{ item.folder | default(omit) }}" add_nodes: "{{ item.add_nodes }}" attributes: site: "{{ outer_item.site }}" @@ -313,7 +329,7 @@ automation_user: "{{ checkmk_var_automation_user }}" automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ item.name }}" - folder: "{{ item.folder }}" + folder: "{{ item.folder | default(omit) }}" add_nodes: "{{ item.add_nodes }}" attributes: site: "{{ outer_item.site }}" @@ -342,7 +358,7 @@ automation_user: "{{ checkmk_var_automation_user }}" automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ item.name }}" - folder: "{{ item.folder }}" + folder: "{{ item.folder | default(omit) }}" remove_nodes: "{{ item.remove_nodes }}" attributes: site: "{{ outer_item.site }}" @@ -371,7 +387,7 @@ automation_user: "{{ checkmk_var_automation_user }}" automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ item.name }}" - folder: "{{ item.folder }}" + folder: "{{ item.folder | default(omit) }}" remove_nodes: "{{ item.remove_nodes }}" attributes: site: "{{ outer_item.site }}" @@ -401,7 +417,7 @@ automation_user: "{{ checkmk_var_automation_user }}" automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ item.name }}" - folder: "{{ item.folder }}" + folder: "{{ item.folder | default(omit) }}" state: "absent" delegate_to: localhost run_once: true # noqa run-once[task] @@ -426,7 +442,7 @@ automation_user: "{{ checkmk_var_automation_user }}" automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ item.name }}" - folder: "{{ item.folder }}" + folder: "{{ item.folder | default(omit) }}" state: "absent" delegate_to: localhost run_once: true # noqa run-once[task] @@ -506,7 +522,7 @@ automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ item.name }}" nodes: "{{ item.nodes }}" - folder: "{{ item.folder }}" + folder: "{{ item.folder | default(omit) }}" state: "absent" delegate_to: localhost run_once: true # noqa run-once[task] @@ -519,7 +535,7 @@ automation_user: "{{ checkmk_var_automation_user }}" automation_secret: "{{ checkmk_var_automation_secret }}" name: "{{ item.name }}" - folder: "{{ item.folder }}" + folder: "{{ item.folder | default(omit) }}" state: "absent" delegate_to: localhost run_once: true # noqa run-once[task] diff --git a/tests/integration/targets/host/vars/main.yml b/tests/integration/targets/host/vars/main.yml index 6a8fd31c4..d81b1bb2f 100644 --- a/tests/integration/targets/host/vars/main.yml +++ b/tests/integration/targets/host/vars/main.yml @@ -9,9 +9,10 @@ test_sites: - version: "2.1.0p41" edition: "cre" site: "old_cre" - - version: "2.0.0p39" - edition: "cre" - site: "ancient_cre" + # Temporarily disable due to #596 until the permanent change to remove it lands. + # - version: "2.0.0p39" + # edition: "cre" + # site: "ancient_cre" checkmk_var_folders: - path: /foo @@ -24,6 +25,7 @@ checkmk_var_folders: name: Digital checkmk_hosts: + - name: test0.tld - name: test1.tld folder: "/" - name: test2.tld @@ -36,6 +38,10 @@ checkmk_hosts: folder: "/foo/bar1" checkmk_cluster_hosts: + - name: cluster_test0.tld + nodes: + - "test0.tld" + - "test4.tld" - name: cluster_test1.tld folder: "/" nodes: