|
| 1 | +# Match E2E CI (ubuntu-22.04, ansible-core 2.18.12, molecule 3.6.1, molecule-docker 1.1.0). |
| 2 | +# Requires Python 3.11+ (ansible-core 2.18.x). |
| 3 | +# |
| 4 | +# Internal CA: set EXTRA_CA_BUNDLE to your CA cert (e.g. ~/SammyCA.pem) so pip and |
| 5 | +# molecule trust internal hosts. The Makefile builds a combined bundle (system + extra) |
| 6 | +# and sets SSL_CERT_FILE for the venv. Example: |
| 7 | +# make molecule-env EXTRA_CA_BUNDLE=~/SammyCA.pem |
| 8 | + |
| 9 | +PYTHON ?= python3.11 |
| 10 | +VENV := .venv-ci |
| 11 | +ANSIBLE_CORE := 2.18.12 |
| 12 | +MOLECULE_VER := 3.6.1 |
| 13 | +MOLECULE_DOCKER_VER := 1.1.0 |
| 14 | + |
| 15 | +# Combined CA bundle when using internal CA (system/certifi + EXTRA_CA_BUNDLE) |
| 16 | +CA_BUNDLE := $(VENV)/.ca-bundle.crt |
| 17 | + |
| 18 | +.PHONY: molecule-env molecule-test molecule-converge molecule-destroy help ca-bundle |
| 19 | + |
| 20 | +help: |
| 21 | + @echo "Targets:" |
| 22 | + @echo " make molecule-env Create/update $(VENV) with CI deps (Python 3.11+, ansible-core $(ANSIBLE_CORE))." |
| 23 | + @echo " make molecule-test Run molecule test (default SCENARIO=ubuntu22)." |
| 24 | + @echo " make molecule-converge Run molecule converge for SCENARIO." |
| 25 | + @echo " make molecule-destroy Run molecule destroy for SCENARIO." |
| 26 | + @echo "Override: SCENARIO=ubuntu20 PYTHON=python3.12 EXTRA_CA_BUNDLE=~/SammyCA.pem" |
| 27 | + |
| 28 | +# Build combined CA bundle so SSL verifies both public and internal (e.g. Artifactory) certs. |
| 29 | +# Uses system/certifi default bundle + EXTRA_CA_BUNDLE. Only built when EXTRA_CA_BUNDLE is set. |
| 30 | +$(CA_BUNDLE): |
| 31 | + @mkdir -p $(VENV) |
| 32 | + @if [ -n "$(EXTRA_CA_BUNDLE)" ]; then \ |
| 33 | + extra="$(EXTRA_CA_BUNDLE)"; \ |
| 34 | + case "$$extra" in ~*) extra="$(HOME)$${extra#\~}";; esac; \ |
| 35 | + [ -f "$$extra" ] || { echo "EXTRA_CA_BUNDLE not found: $$extra"; exit 1; }; \ |
| 36 | + if [ ! -f "$$extra" ]; then echo "EXTRA_CA_BUNDLE not found: $(EXTRA_CA_BUNDLE)"; exit 1; fi; \ |
| 37 | + default=$$($(PYTHON) -c "import ssl, os; p=ssl.get_default_verify_paths(); f=getattr(p,'openssl_cafile',None); print(f if f and os.path.isfile(f) else '')" 2>/dev/null); \ |
| 38 | + [ -n "$$default" ] || default=$$($(PYTHON) -c "import certifi; print(certifi.where())" 2>/dev/null); \ |
| 39 | + [ -n "$$default" ] || { echo "Could not find system CA bundle (install certifi?)"; exit 1; }; \ |
| 40 | + cat "$$default" "$$extra" > $(CA_BUNDLE); \ |
| 41 | + echo "Using CA bundle: $(CA_BUNDLE) (system + $$extra)"; \ |
| 42 | + else \ |
| 43 | + : > $(CA_BUNDLE); \ |
| 44 | + fi |
| 45 | + |
| 46 | +$(VENV)/.stamp: requirements-ci.txt $(CA_BUNDLE) |
| 47 | + $(PYTHON) -c 'import sys; assert sys.version_info >= (3, 11), "Need Python 3.11+ (ansible-core 2.18)"' |
| 48 | + $(PYTHON) -m venv $(VENV) |
| 49 | + @if [ -n "$(EXTRA_CA_BUNDLE)" ] && [ -f $(CA_BUNDLE) ] && [ -s $(CA_BUNDLE) ]; then \ |
| 50 | + export SSL_CERT_FILE="$(CURDIR)/$(CA_BUNDLE)" REQUESTS_CA_BUNDLE="$(CURDIR)/$(CA_BUNDLE)"; \ |
| 51 | + $(VENV)/bin/pip install --upgrade pip; \ |
| 52 | + $(VENV)/bin/pip install -r requirements-ci.txt; \ |
| 53 | + else \ |
| 54 | + $(VENV)/bin/pip install --upgrade pip; \ |
| 55 | + $(VENV)/bin/pip install -r requirements-ci.txt; \ |
| 56 | + fi |
| 57 | + @if [ -n "$(EXTRA_CA_BUNDLE)" ] && [ -f $(CA_BUNDLE) ] && [ -s $(CA_BUNDLE) ]; then \ |
| 58 | + export SSL_CERT_FILE="$(CURDIR)/$(CA_BUNDLE)" REQUESTS_CA_BUNDLE="$(CURDIR)/$(CA_BUNDLE)"; \ |
| 59 | + $(VENV)/bin/ansible-galaxy collection install -r test/requirements.yml; \ |
| 60 | + else \ |
| 61 | + $(VENV)/bin/ansible-galaxy collection install -r test/requirements.yml; \ |
| 62 | + fi |
| 63 | + touch $(VENV)/.stamp |
| 64 | + |
| 65 | +molecule-env: $(VENV)/.stamp |
| 66 | + @echo "Use: $(VENV)/bin/molecule test --scenario-name <scenario>" |
| 67 | + @$(VENV)/bin/ansible --version |
| 68 | + |
| 69 | +# Ensure PATH uses CI venv so molecule and ansible-playbook both use .venv-ci |
| 70 | +MOLECULE_PATH := $(CURDIR)/$(VENV)/bin:$(PATH) |
| 71 | + |
| 72 | +# Export CA bundle for molecule so Ansible/requests inside molecule also trust internal CA |
| 73 | +molecule-test: molecule-env |
| 74 | + @if [ -n "$(EXTRA_CA_BUNDLE)" ] && [ -f $(CA_BUNDLE) ] && [ -s $(CA_BUNDLE) ]; then \ |
| 75 | + export SSL_CERT_FILE="$(CURDIR)/$(CA_BUNDLE)" REQUESTS_CA_BUNDLE="$(CURDIR)/$(CA_BUNDLE)"; \ |
| 76 | + fi; \ |
| 77 | + export PATH="$(MOLECULE_PATH)"; \ |
| 78 | + $(VENV)/bin/molecule test --scenario-name $(or $(SCENARIO),ubuntu22) |
| 79 | + |
| 80 | +molecule-converge: molecule-env |
| 81 | + @if [ -n "$(EXTRA_CA_BUNDLE)" ] && [ -f $(CA_BUNDLE) ] && [ -s $(CA_BUNDLE) ]; then \ |
| 82 | + export SSL_CERT_FILE="$(CURDIR)/$(CA_BUNDLE)" REQUESTS_CA_BUNDLE="$(CURDIR)/$(CA_BUNDLE)"; \ |
| 83 | + fi; \ |
| 84 | + export PATH="$(MOLECULE_PATH)"; \ |
| 85 | + $(VENV)/bin/molecule converge --scenario-name $(or $(SCENARIO),ubuntu22) |
| 86 | + |
| 87 | +molecule-destroy: molecule-env |
| 88 | + @if [ -n "$(EXTRA_CA_BUNDLE)" ] && [ -f $(CA_BUNDLE) ] && [ -s $(CA_BUNDLE) ]; then \ |
| 89 | + export SSL_CERT_FILE="$(CURDIR)/$(CA_BUNDLE)" REQUESTS_CA_BUNDLE="$(CURDIR)/$(CA_BUNDLE)"; \ |
| 90 | + fi; \ |
| 91 | + export PATH="$(MOLECULE_PATH)"; \ |
| 92 | + $(VENV)/bin/molecule destroy --scenario-name $(or $(SCENARIO),ubuntu22) |
0 commit comments