From 77d10ac75eb729bcd32766254f07781e72add928 Mon Sep 17 00:00:00 2001 From: Tobias Bauriedel Date: Thu, 11 Jan 2024 14:02:14 +0100 Subject: [PATCH 1/4] Add molecule test for repos --- .github/workflows/test_repos.yml | 42 ++++++++++++++++++++++++++++ molecule/repos/collections.yml | 3 ++ molecule/repos/converge.yml | 9 ++++++ molecule/repos/molecule.yml | 18 ++++++++++++ molecule/repos/verify.yml | 8 ++++++ requirements-test.txt | 2 ++ roles/repos/defaults/main.yml | 1 + roles/repos/tasks/Debian.yml | 11 ++++++-- roles/repos/tasks/RedHat.yml | 3 ++ roles/repos/tasks/main.yml | 4 +++ roles/repos/vars/RedHat-CentOS-7.yml | 3 ++ roles/repos/vars/RedHat-RedHat-7.yml | 3 ++ roles/repos/vars/default.yml | 2 -- vagrant/Vagrantfile | 6 ++-- vagrant/playbook.yml | 2 +- 15 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/test_repos.yml create mode 100644 molecule/repos/collections.yml create mode 100644 molecule/repos/converge.yml create mode 100644 molecule/repos/molecule.yml create mode 100644 molecule/repos/verify.yml create mode 100644 roles/repos/vars/RedHat-CentOS-7.yml create mode 100644 roles/repos/vars/RedHat-RedHat-7.yml delete mode 100644 roles/repos/vars/default.yml diff --git a/.github/workflows/test_repos.yml b/.github/workflows/test_repos.yml new file mode 100644 index 0000000..989cfde --- /dev/null +++ b/.github/workflows/test_repos.yml @@ -0,0 +1,42 @@ +--- +name: tbauriedel.influxdb.repos + +on: + pull_request: + branches: + - '*' + +jobs: + repos: + runs-on: ubuntu-latest + + env: + COLLECTION_NAMESPACE: tbauriedel + COLLECTION_NAME: influxdb + + strategy: + matrix: + distro: ['centos7', 'ubuntu2204'] + scenario: ['repos'] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install dependencies ansible + run: | + python3 -m pip install --upgrade pip + python3 -m pip install -r requirements-test.txt + + - name: Install collection + run: | + mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE + cp -a ../ansible-collection-$COLLECTION_NAME ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE/$COLLECTION_NAME + + - name: Test with molecule + run: | + ansible --version + molecule --version + molecule test -s ${{ matrix.scenario }} + env: + MOLECULE_DISTRO: ${{ matrix.distro }} diff --git a/molecule/repos/collections.yml b/molecule/repos/collections.yml new file mode 100644 index 0000000..212649b --- /dev/null +++ b/molecule/repos/collections.yml @@ -0,0 +1,3 @@ +collections: + - name: community.docker + - name: ansible.posix diff --git a/molecule/repos/converge.yml b/molecule/repos/converge.yml new file mode 100644 index 0000000..3883b32 --- /dev/null +++ b/molecule/repos/converge.yml @@ -0,0 +1,9 @@ +--- +- name: Converge + hosts: all + + collections: + - tbauriedel.influxdb + + roles: + - repos diff --git a/molecule/repos/molecule.yml b/molecule/repos/molecule.yml new file mode 100644 index 0000000..175103f --- /dev/null +++ b/molecule/repos/molecule.yml @@ -0,0 +1,18 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: instance + 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/repos/verify.yml b/molecule/repos/verify.yml new file mode 100644 index 0000000..84fcbd4 --- /dev/null +++ b/molecule/repos/verify.yml @@ -0,0 +1,8 @@ +--- +- name: Verify + hosts: all + tasks: + - name: Try to install InfluxDBv2 from included repository + ansible.builtin.package: + name: influxdb2 + state: present diff --git a/requirements-test.txt b/requirements-test.txt index ea8a68f..b1a8a44 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,2 +1,4 @@ ansible ansible-lint +molecule +molecule-docker \ No newline at end of file diff --git a/roles/repos/defaults/main.yml b/roles/repos/defaults/main.yml index 543f79a..40b28bb 100644 --- a/roles/repos/defaults/main.yml +++ b/roles/repos/defaults/main.yml @@ -1,2 +1,3 @@ --- +# default variables for influxdb.repos influxdb_repos_key_url: https://repos.influxdata.com/influxdata-archive.key diff --git a/roles/repos/tasks/Debian.yml b/roles/repos/tasks/Debian.yml index 2441ba0..337d912 100644 --- a/roles/repos/tasks/Debian.yml +++ b/roles/repos/tasks/Debian.yml @@ -1,8 +1,15 @@ --- +#- name: Apt - Add repositiory key +# ansible.builtin.apt_key: +# state: present +# url: "{{ influxdb_repos_key_url }}" + - name: Apt - Add repositiory key - ansible.builtin.apt_key: - state: present + ansible.builtin.get_url: url: "{{ influxdb_repos_key_url }}" + dest: /etc/apt/trusted.gpg.d/influx.asc + mode: '0644' + force: true - name: Apt - Add repository to list ansible.builtin.apt_repository: diff --git a/roles/repos/tasks/RedHat.yml b/roles/repos/tasks/RedHat.yml index 92f5bad..2a2d4c6 100644 --- a/roles/repos/tasks/RedHat.yml +++ b/roles/repos/tasks/RedHat.yml @@ -7,6 +7,9 @@ - name: Yum - Add repository to list ansible.builtin.yum_repository: state: present + enabled: true name: influxdb description: Stable InfluxDB repository baseurl: "{{ influxdb_repos_stable_baseurl }}" + gpgcheck: true + gpgkey: "{{ influxdb_repos_key_url }}" diff --git a/roles/repos/tasks/main.yml b/roles/repos/tasks/main.yml index c6f45ba..fccb3e2 100644 --- a/roles/repos/tasks/main.yml +++ b/roles/repos/tasks/main.yml @@ -4,6 +4,10 @@ vars: params: files: + - "{{ ansible_os_family }}-{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml" + - "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml" + - "{{ ansible_os_family }}-{{ ansible_distribution }}.yml" + - "{{ ansible_os_family }}-{{ ansible_lsb.id if ansible_lsb.id is defined else ansible_distribution }}.yml" - "{{ ansible_os_family }}.yml" - default.yml paths: diff --git a/roles/repos/vars/RedHat-CentOS-7.yml b/roles/repos/vars/RedHat-CentOS-7.yml new file mode 100644 index 0000000..21450d1 --- /dev/null +++ b/roles/repos/vars/RedHat-CentOS-7.yml @@ -0,0 +1,3 @@ +--- +influxdb_repos_key_url: https://repos.influxdata.com/influxdata-archive_compat.key +influxdb_repos_stable_baseurl: "https://repos.influxdata.com/rhel/$releasever/$basearch/stable" diff --git a/roles/repos/vars/RedHat-RedHat-7.yml b/roles/repos/vars/RedHat-RedHat-7.yml new file mode 100644 index 0000000..21450d1 --- /dev/null +++ b/roles/repos/vars/RedHat-RedHat-7.yml @@ -0,0 +1,3 @@ +--- +influxdb_repos_key_url: https://repos.influxdata.com/influxdata-archive_compat.key +influxdb_repos_stable_baseurl: "https://repos.influxdata.com/rhel/$releasever/$basearch/stable" diff --git a/roles/repos/vars/default.yml b/roles/repos/vars/default.yml deleted file mode 100644 index 746d187..0000000 --- a/roles/repos/vars/default.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# default variables for influxdb.repos diff --git a/vagrant/Vagrantfile b/vagrant/Vagrantfile index 511e636..fb79b49 100644 --- a/vagrant/Vagrantfile +++ b/vagrant/Vagrantfile @@ -4,7 +4,7 @@ Vagrant.configure("2") do |config| config.vm.define "ubuntu" do |ubuntu| ubuntu.vm.hostname = "influxdb-ubuntu" - ubuntu.vm.box = "bento/ubuntu-22.04" + ubuntu.vm.box = "bento/ubuntu-20.04" ubuntu.vm.network "forwarded_port", guest: 8086, host: 8086 ubuntu.vm.provision "ansible" do |ansible| ansible.playbook = "playbook.yml" @@ -14,11 +14,11 @@ Vagrant.configure("2") do |config| config.vm.define "centos" do |centos| centos.vm.hostname = "influxdb-centos" - centos.vm.box = "eurolinux-vagrant/centos-stream-9" + centos.vm.box = "centos/7" centos.vm.network "forwarded_port", guest: 8086, host: 8087 centos.vm.provision "ansible" do |ansible| ansible.playbook = "playbook.yml" # ansible.verbose = "vvv" end end -end \ No newline at end of file +end diff --git a/vagrant/playbook.yml b/vagrant/playbook.yml index d11f61b..a355dea 100644 --- a/vagrant/playbook.yml +++ b/vagrant/playbook.yml @@ -19,4 +19,4 @@ roles: - repos - - influxdb + # - influxdb From db417ecbd2b730ec0a7a0b59cb59f202fa12e725 Mon Sep 17 00:00:00 2001 From: Tobias Bauriedel Date: Thu, 11 Jan 2024 17:17:56 +0100 Subject: [PATCH 2/4] Update supported systems --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0b02a81..5662271 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ It was created with the aim of refreshing my Ansible knowledge and getting in to ``` ## Supported systems -| Distribution | Tested on | -|--------------|-----------| -| Ubuntu | 22.04 | -| Centos | 9 Stream | +| Distribution | Tested on | +|--------------|--------------| +| Ubuntu | 22.04 | +| Centos | 7 | From 3d740bf983cc254380b5c2cca606d8740c3247cb Mon Sep 17 00:00:00 2001 From: Tobias Bauriedel Date: Fri, 12 Jan 2024 09:21:06 +0100 Subject: [PATCH 3/4] fix installation --- .github/workflows/test_repos.yml | 2 +- molecule/repos/converge.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_repos.yml b/.github/workflows/test_repos.yml index 989cfde..e630f7f 100644 --- a/.github/workflows/test_repos.yml +++ b/.github/workflows/test_repos.yml @@ -12,7 +12,7 @@ jobs: env: COLLECTION_NAMESPACE: tbauriedel - COLLECTION_NAME: influxdb + COLLECTION_NAME: influxdb2 strategy: matrix: diff --git a/molecule/repos/converge.yml b/molecule/repos/converge.yml index 3883b32..4a6d402 100644 --- a/molecule/repos/converge.yml +++ b/molecule/repos/converge.yml @@ -3,7 +3,7 @@ hosts: all collections: - - tbauriedel.influxdb + - tbauriedel.influxdb2 roles: - repos From 69373ea69b2d447cca7350b82c8786577bf26347 Mon Sep 17 00:00:00 2001 From: Tobias Bauriedel Date: Fri, 12 Jan 2024 18:29:00 +0100 Subject: [PATCH 4/4] 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