Compare commits

..

6 commits

11 changed files with 40 additions and 34 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"
@ -17,12 +13,12 @@
hosts: molecule
gather_facts: true
vars_files:
- ../../../../../../../inventory/group_vars/all/vars.yml
- ../../../../../../../inventory/group_vars/all/vault.yml
- ../../../../../../inventory/group_vars/all/vars.yml
- ../../../../../../inventory/group_vars/all/vault.yml
- ./platform_vars.yml
tasks:
- include_vars: ../../../../../../../inventory/group_vars/all/vars.yml
- include_vars: ../../../../../../../inventory/group_vars/all/vault.yml
- include_vars: ../../../../../../inventory/group_vars/all/vars.yml
- include_vars: ../../../../../../inventory/group_vars/all/vault.yml
- include_vars: ./platform_vars.yml
- name: Platform hostvars
ansible.builtin.debug:

View file

@ -35,7 +35,7 @@ provisioner:
name: ansible
config_options:
defaults:
vault_password_file: ${HOME}/.config/ansible/vault-id
vault_password_file: ${ANSIBLE_VAULT_PASSWORD_FILE}
inventory:
group_vars:
molecule:

View file

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

View file

@ -1,10 +1,10 @@
---
collections:
- name: kubernetes.core
version: 5.0.0
version: 5.1.0
- name: community.general
version: 9.1.0
version: 10.3.0
- name: ansible.utils
version: 5.0.0
version: 5.1.2
- name: moreati.jq
version: 0.2.1

View file

@ -0,0 +1,7 @@
ansible-lint==25.1.3
libvirt-python==11.1.0
molecule-plugins[vagrant]==23.7.0
molecule==25.3.1
pylint==3.3.4
python-vagrant==1.0.0
yamllint==1.35.1

View file

@ -1,15 +1,9 @@
ansible-core==2.17.1
ansible-lint==24.7.0
ansible-core==2.18.3
docker==7.1.0
Jinja2==3.1.4
Jinja2==3.1.6
jsonschema==4.23.0
molecule==24.7.0
molecule-plugins==23.5.3
netaddr==1.3.0
paramiko==3.4.0
pycurl==7.45.3
pylint==3.2.5
python-vagrant==1.0.0
yamllint==1.35.1
paramiko==3.5.1
pycurl==7.45.6
jq==1.8.0
dnspython==2.6.1
dnspython==2.7.0

0
scripts/reset_virtd.sh Normal file → Executable file
View file

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

View file

@ -22,6 +22,8 @@ tasks:
vault:init:
desc: Create a vault id file in your home directory for encrypting/decrypting vault files
cmds:
- 'pass generate {{.ANSIBLE_PASS_PATH}} {{.ANSIBLE_PASS_LENGTH}} > /dev/null'
- |
pass show {{.ANSIBLE_PASS_PATH}} &> /dev/null ||
pass generate {{.ANSIBLE_PASS_PATH}} {{.ANSIBLE_PASS_LENGTH}} > /dev/null
status:
- 'pass show {{.ANSIBLE_PASS_PATH}} &> /dev/null '
- 'pass show {{.ANSIBLE_PASS_PATH}} &> /dev/null'