From 170f972185190d0db0ac795403f1d6c0f76d4bd3 Mon Sep 17 00:00:00 2001 From: NaeiKinDus Date: Sun, 9 Mar 2025 00:00:00 +0000 Subject: [PATCH] fix(tooling): fixed molecule setup linked to previous path changes --- README.md | 6 +++--- Taskfile.yml | 8 +++++++- .../extensions/molecule/default/converge.yml | 4 ---- .../extensions/molecule/default/requirements.yml | 1 + tasks/tests.yml | 10 +++++----- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 43b6389..07edbfd 100644 --- a/README.md +++ b/README.md @@ -70,16 +70,16 @@ Execute a command using the Python wrapper that activates the virtual env, e.g. *build*: build all docker images available in `/images`, e.g. `task docker:build` #### module:\ -Directly execute a Python module located in `collections/ansible_collections/nullified/infrastructure/plugins/modules` with its default configuration +Directly execute a Python module located in `ansible_collections/nullified/infrastructure/plugins/modules` with its default configuration (typically the path to a test YAML file). Used only for debugging purpose. Example call: `task module:github_artifact`. #### test:collections -Executes molecule tests on each collections declared in `collections/ansible_collections`. Requires the collection to have a working molecule configuration. +Executes molecule tests on each collections declared in `ansible_collections`. Requires the collection to have a working molecule configuration. Useful to ensure playbooks behave as expected using a Docker container. #### test:modules -Run Ansible's sanity tests on each collections declared in `collections/ansible_collections`. +Run Ansible's sanity tests on each collections declared in `ansible_collections`. #### nosey Run `noseyparker`, a tool that aims to find potential data leak such as passwords and security token. diff --git a/Taskfile.yml b/Taskfile.yml index 1a5f982..6471f00 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -10,11 +10,15 @@ includes: env: DOCKER_REPOSITORY: pouncetech/molecule ANSIBLE_VAULT_PASSWORD_FILE: '{{.ROOT_DIR}}/scripts/pass_get_vault_id.sh' + ANSIBLE_LIBRARY: + sh: > + find .venv -name modules -type d -printf "{{.ROOT_DIR}}/%h/%f:" | sed 's/.$//' vars: PYTHON_WRAPPER: '{{.ROOT_DIR}}/scripts/python_wrapper.sh' MOLECULE_DIR: '{{.ROOT_DIR}}/ansible_collections/nullified/infrastructure/extensions' COLLECTIONS_DIR: '{{.ROOT_DIR}}/ansible_collections' + GALAXY_COLLECTIONS_DIR: '{{.ROOT_DIR}}/galaxy' ANSIBLE_PASS_PATH: ansible/vault-id ANSIBLE_PASS_LENGTH: 50 @@ -64,6 +68,8 @@ tasks: desc: execute a molecule command dir: '{{.MOLECULE_DIR}}' cmd: '{{.PYTHON_WRAPPER}} molecule {{.CLI_ARGS}}' + env: + ANSIBLE_COLLECTIONS_PATH: '{{.COLLECTIONS_DIR}}:{{.GALAXY_COLLECTIONS_DIR}}' molecule:purge: desc: purge libvirtd and reset firewall rules @@ -90,7 +96,7 @@ tasks: desc: create a new collection vars: COLLECTION_NAME: '{{index .MATCH 0}}' - COLLECTION_SUBPATH: 'collections/ansible_collections' + COLLECTION_SUBPATH: 'ansible_collections' cmds: - '{{.PYTHON_WRAPPER}} ansible-galaxy collection init {{.COLLECTION_NAME}} --init-path {{.COLLECTIONS_DIR}}' - 'echo "!{{.COLLECTION_SUBPATH}}/{{(.COLLECTION_NAME | split ".")._0}}" | tee -a .gitignore > /dev/null' diff --git a/ansible_collections/nullified/infrastructure/extensions/molecule/default/converge.yml b/ansible_collections/nullified/infrastructure/extensions/molecule/default/converge.yml index 016d68a..2b76a27 100644 --- a/ansible_collections/nullified/infrastructure/extensions/molecule/default/converge.yml +++ b/ansible_collections/nullified/infrastructure/extensions/molecule/default/converge.yml @@ -3,10 +3,6 @@ - name: Fail if molecule group is missing hosts: localhost tasks: - - name: Print some info - ansible.builtin.debug: - msg: "{{ groups }}" - - name: Assert group existence ansible.builtin.assert: that: "'molecule' in groups" diff --git a/ansible_collections/nullified/infrastructure/extensions/molecule/default/requirements.yml b/ansible_collections/nullified/infrastructure/extensions/molecule/default/requirements.yml index 6a4a42e..c9cc33d 100644 --- a/ansible_collections/nullified/infrastructure/extensions/molecule/default/requirements.yml +++ b/ansible_collections/nullified/infrastructure/extensions/molecule/default/requirements.yml @@ -2,3 +2,4 @@ collections: - community.docker - ansible.netcommon - kubernetes.core + - community.vagrant diff --git a/tasks/tests.yml b/tasks/tests.yml index 4a291c2..88f8621 100644 --- a/tasks/tests.yml +++ b/tasks/tests.yml @@ -3,7 +3,7 @@ version: '3' tasks: modules: desc: run `ansible-test sanity` on collections to find common issues for modules and collections - dir: collections/ansible_collections + dir: ansible_collections vars: ANSIBLE_COLLECTIONS: sh: find -mindepth 2 -maxdepth 2 -type d @@ -11,7 +11,7 @@ tasks: - for: { var: ANSIBLE_COLLECTIONS } task: 'test:module:sanity' vars: - COLLECTION_PATH: 'collections/ansible_collections/{{.ITEM}}' + COLLECTION_PATH: 'ansible_collections/{{.ITEM}}' module:sanity: internal: true @@ -21,7 +21,7 @@ tasks: collections: desc: run molecule tests for all roles and collections. - dir: collections/ansible_collections + dir: ansible_collections vars: ANSIBLE_COLLECTIONS: sh: find -mindepth 2 -maxdepth 2 -type d @@ -29,7 +29,7 @@ tasks: - for: { var: ANSIBLE_COLLECTIONS } task: 'test:collection:molecule' vars: - COLLECTION_PATH: 'collections/ansible_collections/{{.ITEM}}' + COLLECTION_PATH: 'ansible_collections/{{.ITEM}}' collection:molecule: internal: true @@ -40,7 +40,7 @@ tasks: module:github_artifact: desc: run a module from the collection for testing purposes vars: - PLUGINS_DIR: '{{.ROOT_DIR}}/collections/ansible_collections/nullified/infrastructure/plugins' + PLUGINS_DIR: '{{.ROOT_DIR}}/ansible_collections/nullified/infrastructure/plugins' cmd: | {{.PYTHON_WRAPPER}} python3 {{.PLUGINS_DIR}}/modules/github_artifact.py {{.PLUGINS_DIR}}/tests/github_artifact.json | {{.PYTHON_WRAPPER}} python3 -m json.tool | {{.PYTHON_WRAPPER}} pygmentize -l json