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

Rework Molecule scenarios to work with non-root users (sudo) #243

Merged
merged 4 commits into from
Mar 12, 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
56 changes: 43 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
---
name: CI
on:
---
name: CI

on:
pull_request:
push:
push:
branches:
- main
jobs:
test:

jobs:
test:
name: molecule
runs-on: ubuntu-latest
steps:

steps:
- name: Checkout the codebase.
uses: actions/checkout@v2

- name: Set up Python3.
uses: actions/setup-python@v2
with:
python-version: '3.10'

- name: Install testing dependencies.
run: |
python -m pip install --upgrade pip
Expand All @@ -32,10 +32,40 @@ jobs:
ansible-lint --version
ansible-lint -v

- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
cache: 'pip'

- name: Install ansible and molecule
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
retry_wait_seconds: 60
max_attempts: 3
command: |
python -m pip install --upgrade pip
pip install --progress-bar off 'molecule>=5.0.1' 'molecule-plugins[docker]>=23.0.0' ansible-core==${{ matrix.ansible_version }}
if [ -f ansible_collections/${{ inputs.fqcn }}/requirements.txt ]; then
echo "=== Installing python deps"
pip install --progress-bar off -r ansible_collections/${{ inputs.fqcn }}/requirements.txt
fi
if [ -f ansible_collections/${{ inputs.fqcn }}/requirements.yml ]; then
echo "=== Installing dependencies"
ansible-galaxy collection install -r ansible_collections/${{ inputs.fqcn }}/requirements.yml -p /home/runner/.ansible/collections --force-with-deps
fi
if [ -f ansible_collections/${{ inputs.fqcn }}/molecule/requirements.yml ]; then
echo "=== Installing test dependencies"
ansible-galaxy role install -r ansible_collections/${{ inputs.fqcn }}/molecule/requirements.yml ||:
ansible-galaxy collection install -r ansible_collections/${{ inputs.fqcn }}/molecule/requirements.yml -p /home/runner/.ansible/collections
fi
exit 0

- name: "Run molecule tests"
run: molecule test --all
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
MOLECULE_DISTRO: rhel-8
MOLECULE_DISTRO: rhel-8
working-directory: '.'
15 changes: 8 additions & 7 deletions molecule/account/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
---
dependency:
name: galaxy
options:
ignore-certs: True
ignore-errors: True
requirements-file: molecule/default/requirements.yml
driver:
name: podman
platforms:
Expand All @@ -17,18 +11,25 @@ platforms:
- sudo
provisioner:
name: ansible
config_options:
defaults:
interpreter_python: auto_silent
ssh_connection:
pipelining: false
playbooks:
prepare: prepare.yml
converge: converge.yml
verify: verify.yml
env:
ANSIBLE_FORCE_COLOR: "true"
ANSIBLE_ROLES_PATH: "../../roles"
verifier:
name: ansible
scenario:
test_sequence:
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
Expand Down
8 changes: 8 additions & 0 deletions molecule/account/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Prepare
hosts: all
gather_facts: yes
tasks:

- name: "Include common prepare tasks"
ansible.builtin.include_tasks: ../prepare.yml
1 change: 1 addition & 0 deletions molecule/account/verify.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
- name: Verify for account role
hosts: all
become: yes
vars_files:
- vars.yml
gather_facts: false
Expand Down
1 change: 1 addition & 0 deletions molecule/aphrodite/converge.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
- name: Converge
hosts: all
become: yes
vars_files:
- vars.yml

Expand Down
23 changes: 11 additions & 12 deletions molecule/aphrodite/prepare.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
---
- name: Prepare
hosts: all
gather_facts: yes
vars_files:
- vars.yml
tasks:
- name: Add the user jenkins
ansible.builtin.user:
name: jenkins

- name: Creates directory
ansible.builtin.file:
path: /opt/tools
state: directory
owner: jenkins
group: jenkins
mode: 0644
- name: "Include common prepare tasks"
ansible.builtin.include_tasks: ../prepare.yml
vars:
users:
- "{{ aphrodite_user }}"
dirs:
- { path: /opt/tools, owner: "{{ aphrodite_user }}", group: "{{ aphrodite_user }}" }

- name: "Deploy aphrodite configuration to {{ aphrodite.path }}"
become: yes
ansible.builtin.template:
src: "../../roles/aphrodite/templates/aphrodite.json.j2"
dest: "{{ aphrodite.path }}"
owner: jenkins
group: jenkins
owner: "{{ aphrodite_user }}"
group: "{{ aphrodite_user }}"
mode: 0644
1 change: 1 addition & 0 deletions molecule/aphrodite/vars.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
aphrodite_user: jenkins
aphrodite:
trackers:
bugzilla:
Expand Down
1 change: 1 addition & 0 deletions molecule/aphrodite/verify.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
- name: Verify for aphrodite role
hosts: all
become: yes
vars_files:
- vars.yml
gather_facts: false
Expand Down
2 changes: 1 addition & 1 deletion molecule/bashrc/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ provisioner:
playbooks:
converge: converge.yml
verify: verify.yml
prepare: ../prepare.yml
prepare: prepare.yml
env:
ANSIBLE_ROLES_PATH: "../../roles"
verifier:
Expand Down
8 changes: 8 additions & 0 deletions molecule/bashrc/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Prepare
hosts: all
gather_facts: yes
tasks:

- name: "Include common prepare tasks"
ansible.builtin.include_tasks: ../prepare.yml
13 changes: 6 additions & 7 deletions molecule/cron/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
---
dependency:
name: galaxy
options:
ignore-certs: True
ignore-errors: True
requirements-file: molecule/default/requirements.yml
driver:
name: podman
platforms:
Expand All @@ -17,6 +11,11 @@ platforms:
- sudo
provisioner:
name: ansible
config_options:
defaults:
interpreter_python: auto_silent
ssh_connection:
pipelining: false
playbooks:
converge: converge.yml
verify: verify.yml
Expand All @@ -27,9 +26,9 @@ verifier:
name: ansible
scenario:
test_sequence:
- dependency
- cleanup
- destroy
- syntax
- create
- prepare
- converge
Expand Down
16 changes: 9 additions & 7 deletions molecule/cron/prepare.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
---
- name: Prepare
hosts: all
gather_facts: yes
vars_files:
- vars.yml
tasks:
- name: Creates directory
ansible.builtin.file:
path: /opt/tools
state: directory
owner: root
group: root
mode: 0745

- name: "Include common prepare tasks"
ansible.builtin.include_tasks: ../prepare.yml
vars:
users:
- "{{ aphrodite_user }}"
dirs:
- { path: '/opt/tools', mode: '0745' }
1 change: 1 addition & 0 deletions molecule/fast_yum_install/converge.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
- name: Converge
hosts: all
become: yes
vars_files:
- vars.yml
tasks:
Expand Down
1 change: 1 addition & 0 deletions molecule/fast_yum_install/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ platforms:
provisioner:
name: ansible
playbooks:
prepare: prepare.yml
converge: converge.yml
verify: verify.yml
env:
Expand Down
8 changes: 8 additions & 0 deletions molecule/fast_yum_install/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Prepare
hosts: all
gather_facts: yes
tasks:

- name: "Include common prepare tasks"
ansible.builtin.include_tasks: ../prepare.yml
19 changes: 9 additions & 10 deletions molecule/git/prepare.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
---
- name: Prepare
hosts: all
gather_facts: yes
vars_files:
- vars.yml
tasks:
- name: Add the user jenkins
ansible.builtin.user:
name: jenkins
- name: Creates directory
ansible.builtin.file:
path: /home/jenkins
state: directory
owner: jenkins
group: jenkins
mode: 0644

- name: "Include common prepare tasks"
ansible.builtin.include_tasks: ../prepare.yml
vars:
users:
- "{{ git_user }}"
dirs:
- { path: /home/jenkins, owner: "{{ git_user }}", group: "{{ git_user }}" }
3 changes: 2 additions & 1 deletion molecule/git/vars.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
git_user: jenkins
git:
ssl:
verify: false
Expand All @@ -10,4 +11,4 @@ git:
- user: jenkins
email: [email protected]
name: "JBoss SET"
home: "/home/jenkins/"
home: "/home/jenkins/"
1 change: 1 addition & 0 deletions molecule/hosts/converge.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
- name: Converge
hosts: all
become: yes
vars_files:
- vars.yml
tasks:
Expand Down
20 changes: 8 additions & 12 deletions molecule/hosts/prepare.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
---
- name: Prepare
hosts: all
gather_facts: yes
vars_files:
- vars.yml
tasks:
- name: "Include common prepare tasks"
ansible.builtin.include_tasks: ../prepare.yml
vars:
dirs:
- { path: /etc/fake_hosts, state: touch, mode: 0644 }
- { path: /etc/real_hosts, state: touch, mode: 0644 }

- name: "Include fast_yum_install"
ansible.builtin.include_role:
name: "fast_yum_install"

- name: Creates /etc/fake_hosts directory
ansible.builtin.file:
path: /etc/fake_hosts
state: touch
mode: 0644

- name: Creates /etc/real_hosts directory
ansible.builtin.file:
path: /etc/real_hosts
state: touch
mode: 0644
1 change: 1 addition & 0 deletions molecule/hosts/verify.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
- name: Verify for hosts role
hosts: all
become: yes
vars_files:
- vars.yml
gather_facts: false
Expand Down
Loading
Loading