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

Feature/molecule update #663

Merged
merged 35 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
35a4d54
Migrates role to molecule 6
rhysmeister Jul 22, 2024
0800562
Migrate role to molecule 6
rhysmeister Jul 23, 2024
aa8cac7
Migrate role to molecule 6
rhysmeister Jul 23, 2024
bf3dca8
Migrate role to molecule 6
rhysmeister Jul 23, 2024
3fe11a3
Migrate role to molecule 6
rhysmeister Jul 23, 2024
7635cb5
Migrate role to molecule 6
rhysmeister Jul 24, 2024
ebc832e
Migrate role to molecule 6
rhysmeister Jul 24, 2024
23d9cf3
Migrate role to molecule 6
rhysmeister Jul 24, 2024
761574f
Update workflow to install latest molecule
rhysmeister Jul 24, 2024
dc61671
Install molecule-docker
rhysmeister Jul 24, 2024
e1b16a2
Install pytest
rhysmeister Jul 24, 2024
e8643c4
Replace pytest with pytest-testinfra and pep8
rhysmeister Jul 24, 2024
c21f03e
Try pinned version of testinfra
rhysmeister Jul 24, 2024
8bf8b90
Bump testinfra to oldest available
rhysmeister Jul 24, 2024
fb1902b
Bump testinfra to oldest available
rhysmeister Jul 24, 2024
0119456
Add debug code
rhysmeister Jul 24, 2024
36667b6
Add debug code
rhysmeister Jul 24, 2024
ec8891b
Update path of defaults file
rhysmeister Jul 24, 2024
2bb1644
Update defaults vars file relative path
rhysmeister Jul 24, 2024
7a11746
Adds code for funny, works on my machine, but not in ci issue
rhysmeister Jul 24, 2024
abac062
Added test code
rhysmeister Jul 24, 2024
8c83071
Added test code
rhysmeister Jul 24, 2024
454da7d
Update include_vars function
rhysmeister Jul 25, 2024
fabd00f
Update include_vars function
rhysmeister Jul 25, 2024
40e76b7
Correct directory
rhysmeister Jul 25, 2024
029fa6f
Update specific mongo version
rhysmeister Jul 25, 2024
7a4af98
Install pymongo via package manager for Debian 12
rhysmeister Jul 25, 2024
093874e
Adds break system packages flag
rhysmeister Jul 25, 2024
b382adc
Use diff method
rhysmeister Jul 25, 2024
1ae800a
Fix syntax
rhysmeister Jul 25, 2024
414ac99
Use new include_vars function and pep8
rhysmeister Jul 25, 2024
ab437c2
No changed
rhysmeister Jul 25, 2024
18df2db
Use new include_vars function
rhysmeister Jul 25, 2024
930d7b8
Various molecule.yml changes
rhysmeister Jul 25, 2024
7075fb0
Add task to clean apt cache
rhysmeister Jul 25, 2024
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
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
Loading