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` *build*: build all docker images available in `/images`, e.g. `task docker:build`
#### module:\<module_name\> #### 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. (typically the path to a test YAML file). Used only for debugging purpose.
Example call: `task module:github_artifact`. Example call: `task module:github_artifact`.
#### test:collections #### 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. Useful to ensure playbooks behave as expected using a Docker container.
#### test:modules #### 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 #### nosey
Run `noseyparker`, a tool that aims to find potential data leak such as passwords and security token. 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: env:
DOCKER_REPOSITORY: pouncetech/molecule DOCKER_REPOSITORY: pouncetech/molecule
ANSIBLE_VAULT_PASSWORD_FILE: '{{.ROOT_DIR}}/scripts/pass_get_vault_id.sh' 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: vars:
PYTHON_WRAPPER: '{{.ROOT_DIR}}/scripts/python_wrapper.sh' PYTHON_WRAPPER: '{{.ROOT_DIR}}/scripts/python_wrapper.sh'
MOLECULE_DIR: '{{.ROOT_DIR}}/ansible_collections/nullified/infrastructure/extensions' MOLECULE_DIR: '{{.ROOT_DIR}}/ansible_collections/nullified/infrastructure/extensions'
COLLECTIONS_DIR: '{{.ROOT_DIR}}/ansible_collections' COLLECTIONS_DIR: '{{.ROOT_DIR}}/ansible_collections'
GALAXY_COLLECTIONS_DIR: '{{.ROOT_DIR}}/galaxy'
ANSIBLE_PASS_PATH: ansible/vault-id ANSIBLE_PASS_PATH: ansible/vault-id
ANSIBLE_PASS_LENGTH: 50 ANSIBLE_PASS_LENGTH: 50
@ -64,6 +68,8 @@ tasks:
desc: execute a molecule command desc: execute a molecule command
dir: '{{.MOLECULE_DIR}}' dir: '{{.MOLECULE_DIR}}'
cmd: '{{.PYTHON_WRAPPER}} molecule {{.CLI_ARGS}}' cmd: '{{.PYTHON_WRAPPER}} molecule {{.CLI_ARGS}}'
env:
ANSIBLE_COLLECTIONS_PATH: '{{.COLLECTIONS_DIR}}:{{.GALAXY_COLLECTIONS_DIR}}'
molecule:purge: molecule:purge:
desc: purge libvirtd and reset firewall rules desc: purge libvirtd and reset firewall rules
@ -90,7 +96,7 @@ tasks:
desc: create a new collection desc: create a new collection
vars: vars:
COLLECTION_NAME: '{{index .MATCH 0}}' COLLECTION_NAME: '{{index .MATCH 0}}'
COLLECTION_SUBPATH: 'collections/ansible_collections' COLLECTION_SUBPATH: 'ansible_collections'
cmds: cmds:
- '{{.PYTHON_WRAPPER}} ansible-galaxy collection init {{.COLLECTION_NAME}} --init-path {{.COLLECTIONS_DIR}}' - '{{.PYTHON_WRAPPER}} ansible-galaxy collection init {{.COLLECTION_NAME}} --init-path {{.COLLECTIONS_DIR}}'
- 'echo "!{{.COLLECTION_SUBPATH}}/{{(.COLLECTION_NAME | split ".")._0}}" | tee -a .gitignore > /dev/null' - '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 - name: Fail if molecule group is missing
hosts: localhost hosts: localhost
tasks: tasks:
- name: Print some info
ansible.builtin.debug:
msg: "{{ groups }}"
- name: Assert group existence - name: Assert group existence
ansible.builtin.assert: ansible.builtin.assert:
that: "'molecule' in groups" that: "'molecule' in groups"

View file

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

View file

@ -3,7 +3,7 @@ version: '3'
tasks: tasks:
modules: modules:
desc: run `ansible-test sanity` on collections to find common issues for modules and collections desc: run `ansible-test sanity` on collections to find common issues for modules and collections
dir: collections/ansible_collections dir: ansible_collections
vars: vars:
ANSIBLE_COLLECTIONS: ANSIBLE_COLLECTIONS:
sh: find -mindepth 2 -maxdepth 2 -type d sh: find -mindepth 2 -maxdepth 2 -type d
@ -11,7 +11,7 @@ tasks:
- for: { var: ANSIBLE_COLLECTIONS } - for: { var: ANSIBLE_COLLECTIONS }
task: 'test:module:sanity' task: 'test:module:sanity'
vars: vars:
COLLECTION_PATH: 'collections/ansible_collections/{{.ITEM}}' COLLECTION_PATH: 'ansible_collections/{{.ITEM}}'
module:sanity: module:sanity:
internal: true internal: true
@ -21,7 +21,7 @@ tasks:
collections: collections:
desc: run molecule tests for all roles and collections. desc: run molecule tests for all roles and collections.
dir: collections/ansible_collections dir: ansible_collections
vars: vars:
ANSIBLE_COLLECTIONS: ANSIBLE_COLLECTIONS:
sh: find -mindepth 2 -maxdepth 2 -type d sh: find -mindepth 2 -maxdepth 2 -type d
@ -29,7 +29,7 @@ tasks:
- for: { var: ANSIBLE_COLLECTIONS } - for: { var: ANSIBLE_COLLECTIONS }
task: 'test:collection:molecule' task: 'test:collection:molecule'
vars: vars:
COLLECTION_PATH: 'collections/ansible_collections/{{.ITEM}}' COLLECTION_PATH: 'ansible_collections/{{.ITEM}}'
collection:molecule: collection:molecule:
internal: true internal: true
@ -40,7 +40,7 @@ tasks:
module:github_artifact: module:github_artifact:
desc: run a module from the collection for testing purposes desc: run a module from the collection for testing purposes
vars: vars:
PLUGINS_DIR: '{{.ROOT_DIR}}/collections/ansible_collections/nullified/infrastructure/plugins' PLUGINS_DIR: '{{.ROOT_DIR}}/ansible_collections/nullified/infrastructure/plugins'
cmd: | cmd: |
{{.PYTHON_WRAPPER}} python3 {{.PLUGINS_DIR}}/modules/github_artifact.py {{.PLUGINS_DIR}}/tests/github_artifact.json | {{.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 {{.PYTHON_WRAPPER}} python3 -m json.tool | {{.PYTHON_WRAPPER}} pygmentize -l json