Skip to content

Commit

Permalink
Merge pull request #262 from bbaassssiiee/feature/localhost
Browse files Browse the repository at this point in the history
Feature: molecule verify -s localhost
  • Loading branch information
uk-bolly committed Mar 17, 2023
2 parents 4ec75d6 + 12912e7 commit 0142a9b
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ Molecule can be used to work on this role and test in distinct _scenarios_.
```bash
molecule test -s default
molecule converge -s wsl -- --check
molecule verify -s localhost
```

local testing uses:
Expand Down
18 changes: 18 additions & 0 deletions molecule/localhost/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
# This is a playbook to test the tasks.
- name: Converge
hosts: all
become: true
gather_facts: true

vars:
ansible_user: "{{ lookup('env', 'USER') }}"
role_name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
rhel8cis_rule_5_3_4: false

pre_tasks:
tasks:
- name: "Include tasks"
ansible.builtin.include_role:
name: "{{ role_name }}"

30 changes: 30 additions & 0 deletions molecule/localhost/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
# Molecule configuration
# https://molecule.readthedocs.io/en/latest/

driver:
name: delegated
options:
managed: false
ansible_connection_options:
ansible_connection: local
platforms:
- name: localhost

provisioner:
name: ansible
config_options:
defaults:
interpreter_python: auto_silent
stdout_callback: yaml
callbacks_enabled: profile_tasks, timer

lint: |
set -e
yamllint .
ansible-lint
flake8
verifier:
name: ansible

14 changes: 14 additions & 0 deletions molecule/localhost/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Verify
hosts: all
gather_facts: false
become: true

vars:
role_name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"

tasks:
- name: "Include verify tasks"
ansible.builtin.include_role:
name: "{{ role_name }}"
tasks_from: verify
19 changes: 19 additions & 0 deletions tasks/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---

- name: Install openscap
ansible.builtin.dnf:
state: present
name:
- openscap-scanner
- scap-security-guide

- name: Run CIS oscap scan and create /tmp/report.html
ansible.builtin.command:
oscap xccdf eval \
--report /tmp/report.html
--profile cis
--fetch-remote-resources
/usr/share/xml/scap/ssg/content/ssg-almalinux8-ds.xml
changed_when: true
no_log: false
ignore_errors: true

0 comments on commit 0142a9b

Please sign in to comment.