1- # Copywrite Check Tool: https://github.com/hashicorp/copywrite
2- license : license/headers/check
1+ # Ansible Role Makefile
2+ # Copyright (c) Mondoo, Inc.
33
4- license/headers/check :
4+ .PHONY : help
5+ .DEFAULT_GOAL := help
6+
7+ # Colors for help output
8+ CYAN := \033[36m
9+ YELLOW := \033[33m
10+ GREEN := \033[32m
11+ RED := \033[31m
12+ RESET := \033[0m
13+
14+ # Check if virtual environment is activated
15+ define check_venv
16+ @if [ -z "$$VIRTUAL_ENV" ]; then \
17+ echo "$(RED ) ERROR: Virtual environment not activated!$(RESET ) "; \
18+ echo "$(YELLOW ) Run: source molecule-env/bin/activate$(RESET ) "; \
19+ echo "$(YELLOW ) Or first run: make setup/install$(RESET ) "; \
20+ exit 1; \
21+ fi
22+ endef
23+
24+ help : # # Show this help message
25+ @echo " $( CYAN) Ansible Mondoo Role - Available Commands$( RESET) "
26+ @echo " "
27+ @echo " $( YELLOW) Development Setup:$( RESET) "
28+ @grep -E ' ^setup/.*:.*?## .*$$' $(MAKEFILE_LIST ) | \
29+ awk ' BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-28s$(RESET) %s\n", $$1, $$2}'
30+ @echo " "
31+ @echo " $( YELLOW) License Management:$( RESET) "
32+ @grep -E ' ^license/.*:.*?## .*$$' $(MAKEFILE_LIST ) | \
33+ awk ' BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-28s$(RESET) %s\n", $$1, $$2}'
34+ @echo " "
35+ @echo " $( YELLOW) Molecule Testing - Individual Distributions:$( RESET) "
36+ @grep -E ' ^molecule/(ubuntu|debian|rhel|suse)/.*:.*?## .*$$' $(MAKEFILE_LIST ) | \
37+ awk ' BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-28s$(RESET) %s\n", $$1, $$2}' | sort
38+ @echo " "
39+ @echo " $( YELLOW) Molecule Testing - Groups:$( RESET) "
40+ @grep -E ' ^molecule/test/.*:.*?## .*$$' $(MAKEFILE_LIST ) | \
41+ awk ' BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-28s$(RESET) %s\n", $$1, $$2}'
42+ @echo " "
43+ @echo " $( YELLOW) Molecule Lifecycle:$( RESET) "
44+ @grep -E ' ^molecule/(create|converge|verify|destroy|login):.*?## .*$$' $(MAKEFILE_LIST ) | \
45+ awk ' BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-28s$(RESET) %s\n", $$1, $$2}'
46+
47+ # Development Setup
48+ setup/env : # # Setup Python environment with ansible testing tools
49+ @if [ -n " $$ VIRTUAL_ENV" ]; then \
50+ echo " $( RED) ERROR: Virtual environment already activated!$( RESET) " ; \
51+ echo " $( YELLOW) Run 'deactivate' first, then run this command$( RESET) " ; \
52+ exit 1; \
53+ fi
54+ @if [ ! -d " molecule-env" ]; then \
55+ echo " $( YELLOW) Environment not found, creating it first...$( RESET) " ; \
56+ uv venv --python 3.11 --clear molecule-env; \
57+ else \
58+ echo " $( GREEN) Environment exists$( RESET) " ; \
59+ fi
60+ @echo " $( YELLOW) Installing molecule dependencies...$( RESET) "
61+ uv pip install --python molecule-env/bin/python ansible-core==2.18.12 molecule==6.0.3 molecule-docker==2.1.0 ansible-lint jmespath
62+ @echo " $( GREEN) Ansible testing environment ready!$( RESET) "
63+ @echo " $( YELLOW) IMPORTANT: Run 'source molecule-env/bin/activate' before testing$( RESET) "
64+ @echo " $( CYAN) Then you can use: make molecule/debian/12$( RESET) "
65+
66+ setup/dev : # # Configure molecule to test local code instead of installed role (from your home directory)
67+ @echo " $( YELLOW) Configuring molecule for local development testing...$( RESET) "
68+ @printf " [defaults]\nroles_path = ./roles\n" > ansible.cfg
69+ @rm -rf roles/
70+ @mkdir -p roles
71+ @ln -sf ../.. roles/ansible-mondoo
72+ @echo " $( GREEN) Molecule configured to test local repository code!$( RESET) "
73+ @echo " $( CYAN) Tests will now use your current changes, not installed Galaxy role$( RESET) "
74+
75+ setup/clean : # # Clean local development environment
76+ @echo " $( YELLOW) Cleaning local development environment...$( RESET) "
77+ @rm -f ansible.cfg
78+ @rm -rf roles/
79+ @echo " $( GREEN) Local development environment cleaned!$( RESET) "
80+
81+ setup/reset : # # Clean everything including virtual environment
82+ @echo " $( YELLOW) Resetting all development environments...$( RESET) "
83+ @rm -f ansible.cfg
84+ @rm -rf roles/
85+ @rm -rf molecule-env/
86+ @echo " $( GREEN) All development environments reset!$( RESET) "
87+
88+ # Linting
89+ lint : # # Run ansible-lint on the role
90+ @echo " $( YELLOW) Running ansible-lint...$( RESET) "
91+ @molecule-env/bin/ansible-lint .
92+
93+ # License Management
94+ license/headers/check : # # Check license headers
595 copywrite headers --plan
696
7- license/headers/apply :
8- copywrite headers
97+ license/headers/apply : # # Apply license headers
98+ copywrite headers
99+
100+ # Molecule Testing - Ubuntu
101+ molecule/ubuntu/2204 : # # Test with Ubuntu 22.04
102+ $(call check_venv)
103+ @export image=geerlingguy/docker-ubuntu2204-ansible tag=latest && molecule test -s default
104+
105+ molecule/ubuntu/2404 : # # Test with Ubuntu 24.04
106+ $(call check_venv)
107+ @export image=geerlingguy/docker-ubuntu2404-ansible tag=latest && molecule test -s default
108+
109+ # Molecule Testing - Debian
110+ molecule/debian/12 : # # Test with Debian 12
111+ $(call check_venv)
112+ @export image=geerlingguy/docker-debian12-ansible tag=latest && molecule test -s default
113+
114+ molecule/debian/13 : # # Test with Debian 13
115+ $(call check_venv)
116+ @export image=geerlingguy/docker-debian13-ansible tag=latest && molecule test -s default
117+
118+ # Molecule Testing - RHEL Family
119+ molecule/rhel/rocky9 : # # Test with Rocky Linux 9
120+ $(call check_venv)
121+ @export image=geerlingguy/docker-rockylinux9-ansible tag=latest && molecule test -s default
122+
123+ molecule/rhel/fedora40 : # # Test with Fedora 40
124+ $(call check_venv)
125+ @export image=geerlingguy/docker-fedora40-ansible tag=latest && molecule test -s default
126+
127+ # Molecule Testing - SUSE Family
128+ molecule/suse/opensuse : # # Test with openSUSE
129+ $(call check_venv)
130+ @export image=rsprta/opensuse-ansible tag=latest && molecule test -s default
131+
132+ # Molecule Lifecycle Management
133+ molecule/create : # # Create test environment
134+ molecule create -s default
135+
136+ molecule/converge : # # Apply role to test environment
137+ molecule converge -s default
138+
139+ molecule/verify : # # Run verification tests
140+ molecule verify -s default
141+
142+ molecule/destroy : # # Destroy test environment
143+ molecule destroy -s default
144+
145+ molecule/login : # # Login to test environment
146+ molecule login -s default
147+
148+ # Comprehensive Testing
149+ molecule/test/all : # # Run tests on all supported distributions
150+ @echo " $( YELLOW) Testing all distributions...$( RESET) "
151+ @make molecule/ubuntu/2204
152+ @make molecule/ubuntu/2404
153+ @make molecule/debian/12
154+ @make molecule/debian/13
155+ @make molecule/rhel/rocky9
156+ @make molecule/rhel/fedora40
157+ @make molecule/suse/opensuse
158+ @echo " $( GREEN) All tests completed!$( RESET) "
159+
160+ # Quick Testing
161+ molecule/test/debian : # # Test all Debian-based distributions
162+ @echo " $( YELLOW) Testing Debian distributions...$( RESET) "
163+ @make molecule/ubuntu/2204
164+ @make molecule/ubuntu/2404
165+ @make molecule/debian/12
166+ @make molecule/debian/13
167+
168+ molecule/test/rhel : # # Test all RHEL-based distributions
169+ @echo " $( YELLOW) Testing RHEL distributions...$( RESET) "
170+ @make molecule/rhel/rocky9
171+ @make molecule/rhel/fedora40
0 commit comments