Skip to content

Commit

Permalink
Added Molecule tests for atomic-red-team role.
Browse files Browse the repository at this point in the history
**Added:**

- Molecule configuration - Created new `molecule` configuration files for the
  `atomic-red-team` role to support local testing and verification.
- Converge playbook - Added `converge.yml` playbook for applying the role during
  testing.
- Inventory file - Created an inventory file for Molecule testing.
- Docker platforms - Defined Docker platforms in `molecule.yml` for testing the
  role on Ubuntu, Kali, and Rocky Linux containers.
- Verify playbook - Added `verify.yml` playbook for verifying the role's
  functionality during testing.
  • Loading branch information
l50 committed Apr 6, 2024
1 parent 64ec48d commit 430d9ff
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
13 changes: 13 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Converge
hosts: all
tasks:
- name: Include default variables
ansible.builtin.include_vars:
file: "../../defaults/main.yml"
- name: Include variables
ansible.builtin.include_vars:
file: "../../vars/main.yml"
roles:
- name: Run the atomic-red-team role
role: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
1 change: 1 addition & 0 deletions molecule/default/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localhost
41 changes: 41 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
# Run molecule inside of a docker container
driver:
name: docker

platforms:
- name: ubuntu-atomic-red-team
image: "geerlingguy/docker-ubuntu2204-ansible:latest"
# Setting the command to this is necessary for systemd containers
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true

- name: kali-atomic-red-team
image: cisagov/docker-kali-ansible:latest
# Setting the command to this is necessary for systemd containers
command: ""
pre_build_image: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true

- name: redhat-atomic-red-team
image: "geerlingguy/docker-rockylinux9-ansible:latest"
# Setting the command to this is necessary for systemd containers
command: ""
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true

provisioner:
name: ansible
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}

verifier:
name: ansible
34 changes: 34 additions & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Verify
hosts: all
gather_facts: true
tasks:
- name: Include default variables
ansible.builtin.include_vars:
file: "../../defaults/main.yml"

- name: Include variables
ansible.builtin.include_vars:
file: "../../vars/main.yml"

- name: Check if PowerShell is installed
ansible.builtin.shell:
cmd: "pwsh -NoProfile -v"
register: pwsh_version
ignore_errors: true

- name: Assert that PowerShell is installed
ansible.builtin.assert:
that:
- pwsh_version.rc == 0
- "'PowerShell' in pwsh_version.stdout"

- name: Check if /usr/local/bin is in $PATH
ansible.builtin.shell:
cmd: "echo $PATH"
register: system_path

- name: Assert that /usr/local/bin is in $PATH
ansible.builtin.assert:
that:
- "'/usr/local/bin' in system_path.stdout"

0 comments on commit 430d9ff

Please sign in to comment.