This repository uses pre-commit hooks to ensure code quality and consistency. The configuration is set up to work with Ansible projects, including playbooks with encrypted vault files.
-
Install pre-commit:
pip install pre-commit
-
Install the hooks in your local repository:
pre-commit install
There are two ways to run the pre-commit hooks:
-
Standard way - Will run all hooks including ansible-lint:
./pre-commit-run.sh run --all-files
-
During commits - Pre-commit hooks will run automatically when you commit.
The configuration excludes vault files from ansible-lint checks. The pre-commit-run.sh script sets environment variables to help ansible-lint handle vault files without needing the actual vault password.
If you need to bypass ansible-lint during a commit, you can use:
SKIP=ansible-lint git commit -m "Your commit message".pre-commit-config.yaml- Main pre-commit configuration.ansible-lint- Settings for ansible-lint.yamllint- Settings for YAML linting.pre-commit-config-skip.yaml- Patterns for files to exclude from checks
-
Ansible-lint failing on vault files:
- Check that your vault files match the exclusion pattern in
.ansible-lint - Use the
pre-commit-run.shscript to set proper environment variables
- Check that your vault files match the exclusion pattern in
-
YAML linting issues in third-party files:
- The configuration excludes files in
host_files/localhost/nvim/autoload/plugged/andcollections/ - If needed, add additional patterns to
.pre-commit-config-skip.yaml
- The configuration excludes files in
This repository uses a requirements.yml file to manage Ansible collections rather than committing them directly to the repository. The collections/ directory is excluded from git via the .gitignore file.
To install collections:
ansible-galaxy collection install -r requirements.ymlTo add a new collection:
- Edit the
requirements.ymlfile to add the collection name and version - Run the command above to install it
- Never commit collection files directly to the repository