feat!(tasks): move tasks to include; move dependencies installation to a task;...

This commit is contained in:
NaeiKinDus 2025-01-26 22:52:14 +00:00
parent 846f5e693e
commit 35d72db683
8 changed files with 161 additions and 103 deletions

45
tasks/setup_linux.yml Normal file
View file

@ -0,0 +1,45 @@
version: '3'
tasks:
requirements:
desc: install required packages
cmds:
- |
sudo apt install --no-install-recommends --assume-yes \
coreutils \
curl \
libcurl4-openssl-dev \
python3-virtualenv \
python3-dev
venv:
desc: install a Python3 virtualenv and all the required ansible / molecule dependencies.
cmds:
- |
rm -rf ./.venv || true
python3 -m virtualenv --download ./.venv
./.venv/bin/python3 -m pip install --upgrade -r requirements.txt
status:
- test -d ./.venv
ansible:
desc: create or update an ansible.cfg file
cmds:
- ./scripts/generate_ansible_config.sh -o ansible.cfg
status:
- test -f ansible.cfg
galaxy:
desc: install ansible galaxy collections
cmds:
- "{{.PYTHON_WRAPPER}} ansible-galaxy collection install -r ansible_galaxy-requirements.yml"
dev:
desc: install required packages to run molecule, vagrant and other dev tools
cmds:
- ./scripts/setup_dev_env.sh
preconditions:
- sh: test -f ./.venv/bin/python3
msg: virtualenv must be set up first
- sh: test -x /usr/sbin/nft
msg: "nftables is required (tested bin path: /usr/sbin/nft)"

46
tasks/tests.yml Normal file
View file

@ -0,0 +1,46 @@
version: '3'
tasks:
modules:
desc: run `ansible-test sanity` on collections to find common issues for modules and collections
dir: collections/ansible_collections
vars:
ANSIBLE_COLLECTIONS:
sh: find -mindepth 2 -maxdepth 2 -type d
cmds:
- for: { var: ANSIBLE_COLLECTIONS }
task: 'test:module:sanity'
vars:
COLLECTION_PATH: 'collections/ansible_collections/{{.ITEM}}'
module:sanity:
internal: true
dir: '{{.COLLECTION_PATH}}'
cmds:
- 'test -d tests && {{.PYTHON_WRAPPER}} ansible-test sanity --venv || echo - ignored $(pwd)'
collections:
desc: run molecule tests for all roles and collections.
dir: collections/ansible_collections
vars:
ANSIBLE_COLLECTIONS:
sh: find -mindepth 2 -maxdepth 2 -type d
cmds:
- for: { var: ANSIBLE_COLLECTIONS }
task: 'test:collection:molecule'
vars:
COLLECTION_PATH: 'collections/ansible_collections/{{.ITEM}}'
collection:molecule:
internal: true
dir: '{{.COLLECTION_PATH}}/extensions'
cmds:
- 'test -d molecule && {{.PYTHON_WRAPPER}} molecule test || echo - ignored $(pwd)'
module:github_artifact:
desc: run a module from the collection for testing purposes
vars:
PLUGINS_DIR: '{{.ROOT_DIR}}/collections/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