Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add molecule test for repos #8

Merged
merged 5 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/vagrant/.vagrant
/vagrant/.vagrant
.vscode
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
3 changes: 3 additions & 0 deletions molecule/influxdb2/collections.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
collections:
- name: community.docker
- name: ansible.posix
23 changes: 23 additions & 0 deletions molecule/influxdb2/converge.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions molecule/influxdb2/molecule.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions molecule/influxdb2/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Prepare
hosts: all
tasks:
- name: Ensure python3-requests is installed
ansible.builtin.pip:
name: requests
8 changes: 8 additions & 0 deletions molecule/influxdb2/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Verify
hosts: all
tasks:
- name: Ensure service is running
ansible.builtin.service:
name: influxdb
state: started
3 changes: 3 additions & 0 deletions molecule/repos/collections.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
collections:
- name: community.docker
- name: ansible.posix
9 changes: 9 additions & 0 deletions molecule/repos/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Converge
hosts: all

collections:
- tbauriedel.influxdb2

roles:
- repos
18 changes: 18 additions & 0 deletions molecule/repos/molecule.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions molecule/repos/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Verify
hosts: all
tasks:
- name: Try to install InfluxDBv2 from included repository
ansible.builtin.package:
name: influxdb2
state: present
4 changes: 3 additions & 1 deletion plugins/modules/organize_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
'''
Expand Down
4 changes: 3 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
ansible
ansible-core==2.16.2
ansible-lint
molecule
molecule-docker
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
p
2 changes: 1 addition & 1 deletion roles/influxdb2/tasks/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
1 change: 1 addition & 0 deletions roles/repos/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
# default variables for influxdb.repos
influxdb_repos_key_url: https://repos.influxdata.com/influxdata-archive.key
11 changes: 9 additions & 2 deletions roles/repos/tasks/Debian.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
3 changes: 3 additions & 0 deletions roles/repos/tasks/RedHat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
4 changes: 4 additions & 0 deletions roles/repos/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions roles/repos/vars/RedHat-CentOS-7.yml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions roles/repos/vars/RedHat-RedHat-7.yml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 0 additions & 2 deletions roles/repos/vars/default.yml

This file was deleted.

14 changes: 7 additions & 7 deletions vagrant/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
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"
# ansible.verbose = "vvv"
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
end