diff --git a/.github/workflows/molecule.yml b/.github/workflows/molecule.yml new file mode 100644 index 0000000..d1af569 --- /dev/null +++ b/.github/workflows/molecule.yml @@ -0,0 +1,47 @@ +--- +name: Build + +on: + pull_request: + branches: + - '*' + +jobs: + build: + runs-on: ubuntu-latest + + env: + COLLECTION_NAMESPACE: tbauriedel + COLLECTION_NAME: influxdb2 + + strategy: + matrix: + distro: ['rockylinux9', 'ubuntu2204'] + scenario: ['repos', 'influxdb2'] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - 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 + + - 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/.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 761447d..1bd414a 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 | +| 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/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..4a6d402 --- /dev/null +++ b/molecule/repos/converge.yml @@ -0,0 +1,9 @@ +--- +- name: Converge + hosts: all + + collections: + - tbauriedel.influxdb2 + + roles: + - repos diff --git a/molecule/repos/molecule.yml b/molecule/repos/molecule.yml new file mode 100644 index 0000000..31e9a6e --- /dev/null +++ b/molecule/repos/molecule.yml @@ -0,0 +1,18 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: "repos-${MOLECULE_DISTRO}" + 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/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 ea8a68f..a6f6070 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,2 +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/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..4e0373d 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" @@ -12,13 +12,13 @@ Vagrant.configure("2") do |config| end end - config.vm.define "centos" do |centos| - centos.vm.hostname = "influxdb-centos" - centos.vm.box = "eurolinux-vagrant/centos-stream-9" - 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 end -end \ No newline at end of file +end