Skip to content

Commit

Permalink
Feature/molecule update (#663)
Browse files Browse the repository at this point in the history
* Migrates role to molecule 6

* Migrate role to molecule 6

* Migrate role to molecule 6

* Migrate role to molecule 6

* Migrate role to molecule 6

* Migrate role to molecule 6

* Migrate role to molecule 6

* Migrate role to molecule 6

* Update workflow to install latest molecule

* Install molecule-docker

* Install pytest

* Replace pytest with pytest-testinfra and pep8

* Try pinned version of testinfra

* Bump testinfra to oldest available

* Bump testinfra to oldest available

* Add debug code

* Add debug code

* Update path of defaults file

* Update defaults vars file relative path

* Adds code for funny, works on my machine, but not in ci issue

* Added test code

* Added test code

* Update include_vars function

* Update include_vars function

* Correct directory

* Update specific mongo version

* Install pymongo via package manager for Debian 12

* Adds break system packages flag

* Use diff method

* Fix syntax

* Use new include_vars function and pep8

* No changed

* Use new include_vars function

* Various molecule.yml changes

* Add task to clean apt cache
  • Loading branch information
rhysmeister authored Jul 25, 2024
1 parent 3b6daab commit b29b992
Show file tree
Hide file tree
Showing 110 changed files with 676 additions and 2,263 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/test-roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:

jobs:

# TODO - Consider adding ansible-lint and pylint steps as molecule removed these

roles_matrix:
runs-on: ubuntu-20.04
defaults:
Expand Down Expand Up @@ -42,7 +44,7 @@ jobs:
strategy:
matrix:
python_version:
- "3.8"
- "3.11"
mongodb_role: ${{ fromJson(needs.roles_matrix.outputs.matrix) }}

steps:
Expand All @@ -64,8 +66,8 @@ jobs:

- name: Install requirements
run: |
export pyv=$(python -c 'from platform import python_version; print(python_version()[:3])')
pip install --requirement requirements-${pyv}.txt
pip install molecule molecule-docker pytest-testinfra
- name: Add molecule location to path
run: echo "${HOME}/.local/bin" >> $GITHUB_PATH

Expand Down
51 changes: 0 additions & 51 deletions roles/mongodb_auth/molecule/default/Dockerfile.j2

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
---
- name: Converge
hosts: all
become: yes
vars:
# for this test, each machine is an isolated mongod instance
replicaset: false
sharding: false

# initially disable authorization on some hosts
hosts_with_auth_disabled:
- ubuntu_22_04
- ubuntu_22
- ubuntu2204
- debian12
- rockylinux9

# add some users for some of the hosts
hosts_with_extra_user:
- centos_8
#- fedora
- ubuntu_22
- almalinux9
- debian12
- amazon2023
mongodb_users_empty: []
mongodb_users_full:
- db: somedatabase
Expand All @@ -37,16 +37,24 @@
tags: molecule-idempotence-notest # avoids false positive where replacing conf file disables authorization again

tasks:
- name: Add EPEL repo to CentOS 7 to allow installing pip package
become: yes
yum:
name: epel-release
state: present
when: inventory_hostname == 'almalinux_8'
#- name: Add EPEL repo to CentOS 7 to allow installing pip package
# become: yes
# yum:
# name: epel-release
# state: present
# when: inventory_hostname == 'almalinux_8'

- name: Install pymongo
pip:
name: pymongo
when:
- ansible_hostname != "debian12"

- name: Install pymongo on Debian 12
ansible.builtin.command: pip install pymongo --break-system-packages
when:
- ansible_hostname == "debian12"
changed_when: False

- name: Enable mongo auth
include_role:
Expand Down
57 changes: 0 additions & 57 deletions roles/mongodb_auth/molecule/default/molecule.yml

This file was deleted.

1 change: 1 addition & 0 deletions roles/mongodb_auth/molecule/default/molecule.yml
18 changes: 16 additions & 2 deletions roles/mongodb_auth/molecule/default/prepare.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
---
- name: Prepare
hosts: all
become: yes
vars:
redhat_packages:
- net-tools
- python3-pip
- python3-packaging
debian_packages:
- net-tools
tasks:

- name: Ensure epel is available
Expand All @@ -20,4 +23,15 @@
ansible.builtin.package:
name: "{{ redhat_packages }}"
state: present
when: ansible_os_family == "RedHat"
when: ansible_os_family == "RedHat"

- name: Update the APT cache on Debian-based systems
apt:
update_cache: yes
when: ansible_os_family == "Debian"

- name: Install Debian packages
ansible.builtin.package:
name: "{{ debian_packages }}"
state: present
when: ansible_os_family == "Debian"
23 changes: 21 additions & 2 deletions roles/mongodb_auth/molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,29 @@


def include_vars(host):
ansible = host.ansible("include_vars",
'file="../../defaults/main.yml"',
current_dir = os.path.dirname(os.path.abspath(__file__))
path_components = current_dir.split(os.sep)
trim_count = 0
# Weird bug where the path of this file is incorrect
# It seems the ansible module, at least when used here
# Used to run in a different directory, meaning the
# relative path was not correct. This method should mean it's
# always correct whatever the context.
for component in path_components:
if component.startswith("mongodb_"):
break
else:
trim_count += 1
trim_count = (len(path_components) - 1) - trim_count
# Trim off the dirs after the role dir
trimmed_components = path_components[:-trim_count]
trimmed_path = os.sep.join(trimmed_components)
vars_file_path = os.path.join(trimmed_path, 'defaults', 'main.yml')
ansible = host.ansible('include_vars',
f'file="{vars_file_path}"',
False,
False)
# print(str(ansible))
return ansible


Expand Down
54 changes: 0 additions & 54 deletions roles/mongodb_auth/molecule/virtualbox/molecule.yml

This file was deleted.

58 changes: 0 additions & 58 deletions roles/mongodb_auth/molecule/virtualbox/playbook.yml

This file was deleted.

Loading

0 comments on commit b29b992

Please sign in to comment.