Development Environment#
Tools and configuration used in the collection repositories
arillso/ansible.system, arillso/ansible.container and
arillso/ansible.agent. Each repository ships these files itself; this
page describes what is there.
Requirements#
Python in the version pinned in
.python-versionGit
Docker, for Molecule scenarios
Lefthook for the Git hooks
Node.js (
npx), used by theprettierandmarkdownlinthooksgitleaksandactionlintas system binaries for the hooks
Setup#
git clone https://github.com/arillso/ansible.system.git
cd ansible.system
python3 -m venv .venv
source .venv/bin/activate
make install-dev # pip install -r requirements.txt
lefthook install
requirements.txt installs ansible-core>=2.18.0, ansible-lint,
yamllint, ruff, black, molecule,
molecule-plugins[docker], molecule-qemu, pytest,
pytest-ansible and pytest-cov. arillso.system adds tomli-w
for its TOML filters.
Make targets#
make help lists the targets of the current repository. Shared by all
three collections:
Target |
Action |
|---|---|
|
|
|
Runs |
|
|
|
|
|
Removes build artifacts |
Test targets differ: ansible.system has test-unit, coverage,
test-integration and test-molecule; ansible.agent has
test-unit and test-molecule; ansible.container has test (pytest tests/unit/).
Molecule#
Scenario locations:
ansible.system,ansible.agent:extensions/molecule/<scenario>/ansible.container:roles/<role>/molecule/default/
make test-molecule runs every scenario and skips those whose driver
is unavailable, for example when Docker is not running.
Git hooks#
lefthook.yml defines the hooks:
Hook |
Command |
Files |
|---|---|---|
pre-commit |
|
|
pre-commit |
|
|
pre-commit |
|
|
pre-commit |
|
|
pre-commit |
|
|
pre-commit |
|
staged changes |
pre-push |
|
full history |
ansible.container runs ansible-lint with --offline in the hook.
Files under .ansible/ are excluded.
Configuration files#
.editorconfig#
As in ansible.system and ansible.container (ansible.agent adds
indent_size = 2 for JSON):
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.{yml,yaml}]
indent_size = 4
[*.{json,json5}]
indent_size = 4
[*.md]
trim_trailing_whitespace = false
[Makefile]
indent_style = tab
.yamllint.yml#
Identical in all three repositories. It extends default with:
indentation of 4 spaces, sequences indented
line-length500, as warningtruthyallows onlytrueandfalsedocument-startrequired,document-endforbiddenimplicit and explicit octal values forbidden
ignores
.ansible/,.github/,.venv/,venv/,.tox/
.ansible-lint#
All three repositories exclude .ansible/, .github/, .venv/ and
venv/ and skip galaxy[version-incorrect],
command-instead-of-module, no-handler and package-latest.
ansible.system: warns onname[casing]andyaml[line-length]ansible.container:profile: production,strict: true, warns onname[casing]andyaml[line-length]ansible.agent:profile: production,strict: true
The pre-commit hook applies the production profile in every
repository.
Running in the container image#
The arillso/ansible image runs as user
ansible (UID 1000) and contains ansible-core but not
ansible-lint or Molecule. Use it to run playbooks against test hosts:
docker run --rm -it \
-v "$PWD":/workspace -w /workspace \
arillso/ansible bash
Editor#
.editorconfig covers indentation and line endings in most editors.
For VS Code, the Red Hat Ansible extension (redhat.ansible) runs
ansible-lint and picks up .ansible-lint from the repository root.
See also
Quick Start - Install and use the collections
Repository Standards - Repository standards
Contributing - Contribution workflow
CI/CD & Linting - CI workflows