fix(tooling): fixed molecule setup linked to previous path changes

This commit is contained in:
NaeiKinDus 2025-03-09 00:00:00 +00:00
parent a710ec9644
commit 170f972185
Signed by: WoodSmellParticle
GPG key ID: 8E52ADFF7CA8AE56
5 changed files with 16 additions and 13 deletions

View file

@ -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:\<module_name\>
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.

View file

@ -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'

View file

@ -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"

View file

@ -2,3 +2,4 @@ collections:
- community.docker
- ansible.netcommon
- kubernetes.core
- community.vagrant

View file

@ -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