From 69373ea69b2d447cca7350b82c8786577bf26347 Mon Sep 17 00:00:00 2001 From: Tobias Bauriedel Date: Fri, 12 Jan 2024 18:29:00 +0100 Subject: [PATCH] add molecule for influxdb2 --- .../{test_repos.yml => molecule.yml} | 15 ++++++++---- .gitignore | 3 ++- README.md | 2 +- molecule/influxdb2/collections.yml | 3 +++ molecule/influxdb2/converge.yml | 23 +++++++++++++++++++ molecule/influxdb2/molecule.yml | 18 +++++++++++++++ molecule/influxdb2/prepare.yml | 7 ++++++ molecule/influxdb2/verify.yml | 8 +++++++ molecule/repos/molecule.yml | 2 +- plugins/modules/organize_bucket.py | 4 +++- requirements-test.txt | 2 +- requirements.txt | 1 - roles/influxdb2/tasks/setup.yml | 2 +- vagrant/Vagrantfile | 10 ++++---- 14 files changed, 83 insertions(+), 17 deletions(-) rename .github/workflows/{test_repos.yml => molecule.yml} (77%) create mode 100644 molecule/influxdb2/collections.yml create mode 100644 molecule/influxdb2/converge.yml create mode 100644 molecule/influxdb2/molecule.yml create mode 100644 molecule/influxdb2/prepare.yml create mode 100644 molecule/influxdb2/verify.yml diff --git a/.github/workflows/test_repos.yml b/.github/workflows/molecule.yml similarity index 77% rename from .github/workflows/test_repos.yml rename to .github/workflows/molecule.yml index e630f7f..d1af569 100644 --- a/.github/workflows/test_repos.yml +++ b/.github/workflows/molecule.yml @@ -1,5 +1,5 @@ --- -name: tbauriedel.influxdb.repos +name: Build on: pull_request: @@ -7,7 +7,7 @@ on: - '*' jobs: - repos: + build: runs-on: ubuntu-latest env: @@ -16,14 +16,19 @@ jobs: strategy: matrix: - distro: ['centos7', 'ubuntu2204'] - scenario: ['repos'] + distro: ['rockylinux9', 'ubuntu2204'] + scenario: ['repos', 'influxdb2'] steps: - name: Checkout code uses: actions/checkout@v4 - - name: Install dependencies ansible + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Install dependencies run: | python3 -m pip install --upgrade pip python3 -m pip install -r requirements-test.txt diff --git a/.gitignore b/.gitignore index 3be41a7..af16143 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/vagrant/.vagrant \ No newline at end of file +/vagrant/.vagrant +.vscode \ No newline at end of file diff --git a/README.md b/README.md index 7f90c00..1bd414a 100644 --- a/README.md +++ b/README.md @@ -46,4 +46,4 @@ It was created with the aim of refreshing my Ansible knowledge and getting in to | Distribution | Tested on | |--------------|--------------| | Ubuntu | 22.04 | -| Centos | 7 | +| Rocky | 9 | diff --git a/molecule/influxdb2/collections.yml b/molecule/influxdb2/collections.yml new file mode 100644 index 0000000..212649b --- /dev/null +++ b/molecule/influxdb2/collections.yml @@ -0,0 +1,3 @@ +collections: + - name: community.docker + - name: ansible.posix diff --git a/molecule/influxdb2/converge.yml b/molecule/influxdb2/converge.yml new file mode 100644 index 0000000..254612d --- /dev/null +++ b/molecule/influxdb2/converge.yml @@ -0,0 +1,23 @@ +--- +- name: Converge + hosts: all + + vars: + influxdb_influxdb2_admin_token: 123456789abc! + influxdb_influxdb2_buckets: + - name: foobar1 + state: present + org: default + token: "{{ influxdb_influxdb2_admin_token }}" + host: "{{ influxdb_influxdb2_host }}" + retention: + type: 'expire' + everySeconds: 50000 + shardGroupDurationSeconds: 0 + + collections: + - tbauriedel.influxdb2 + + roles: + - repos + - influxdb2 diff --git a/molecule/influxdb2/molecule.yml b/molecule/influxdb2/molecule.yml new file mode 100644 index 0000000..8f822ee --- /dev/null +++ b/molecule/influxdb2/molecule.yml @@ -0,0 +1,18 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: influxdb2 + image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + privileged: true + pre_build_image: true +provisioner: + name: ansible +verifier: + name: ansible diff --git a/molecule/influxdb2/prepare.yml b/molecule/influxdb2/prepare.yml new file mode 100644 index 0000000..addfb56 --- /dev/null +++ b/molecule/influxdb2/prepare.yml @@ -0,0 +1,7 @@ +--- +- name: Prepare + hosts: all + tasks: + - name: Ensure python3-requests is installed + ansible.builtin.pip: + name: requests diff --git a/molecule/influxdb2/verify.yml b/molecule/influxdb2/verify.yml new file mode 100644 index 0000000..c40495f --- /dev/null +++ b/molecule/influxdb2/verify.yml @@ -0,0 +1,8 @@ +--- +- name: Verify + hosts: all + tasks: + - name: Ensure service is running + ansible.builtin.service: + name: influxdb + state: started diff --git a/molecule/repos/molecule.yml b/molecule/repos/molecule.yml index 175103f..31e9a6e 100644 --- a/molecule/repos/molecule.yml +++ b/molecule/repos/molecule.yml @@ -4,7 +4,7 @@ dependency: driver: name: docker platforms: - - name: instance + - name: "repos-${MOLECULE_DISTRO}" image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest" command: ${MOLECULE_DOCKER_COMMAND:-""} cgroupns_mode: host diff --git a/plugins/modules/organize_bucket.py b/plugins/modules/organize_bucket.py index 8f4753f..b0d655b 100644 --- a/plugins/modules/organize_bucket.py +++ b/plugins/modules/organize_bucket.py @@ -2,7 +2,9 @@ # pylint: disable=missing-module-docstring from ansible.module_utils.basic import AnsibleModule -from ansible_collections.tbauriedel.influxdb.plugins.module_utils.utils import (Influx2Api) # pylint: disable=import-error +from ansible_collections.tbauriedel.influxdb2.plugins.module_utils.utils import ( + Influx2Api, +) def run_module(): ''' diff --git a/requirements-test.txt b/requirements-test.txt index b1a8a44..a6f6070 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,4 +1,4 @@ -ansible +ansible-core==2.16.2 ansible-lint molecule molecule-docker \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 4f6c4ee..e69de29 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +0,0 @@ -p \ No newline at end of file diff --git a/roles/influxdb2/tasks/setup.yml b/roles/influxdb2/tasks/setup.yml index 3fba242..ab50df0 100644 --- a/roles/influxdb2/tasks/setup.yml +++ b/roles/influxdb2/tasks/setup.yml @@ -22,7 +22,7 @@ # TODO add handling for orgs, buckets, etc. - name: Organize buckets - tbauriedel.influxdb.organize_bucket: + tbauriedel.influxdb2.organize_bucket: name: "{{ item.name }}" state: "{{ item.state }}" org: "{{ item.org }}" diff --git a/vagrant/Vagrantfile b/vagrant/Vagrantfile index fb79b49..4e0373d 100644 --- a/vagrant/Vagrantfile +++ b/vagrant/Vagrantfile @@ -12,11 +12,11 @@ Vagrant.configure("2") do |config| end end - config.vm.define "centos" do |centos| - centos.vm.hostname = "influxdb-centos" - centos.vm.box = "centos/7" - centos.vm.network "forwarded_port", guest: 8086, host: 8087 - centos.vm.provision "ansible" do |ansible| + config.vm.define "rocky" do |rocky| + rocky.vm.hostname = "influxdb-rocky" + rocky.vm.box = "rockylinux/9" + rocky.vm.network "forwarded_port", guest: 8086, host: 8087 + rocky.vm.provision "ansible" do |ansible| ansible.playbook = "playbook.yml" # ansible.verbose = "vvv" end