mirror of
https://codeberg.org/Tealk/ansible_validation_script.git
synced 2025-11-09 19:41:48 +01:00
A Bash script for validating and checking Ansible playbooks, inventory files, and Jinja2 templates. This script helps ensure the correctness of your Ansible configurations by performing syntax checks, linting, and inventory validation.
| lib | ||
| .gitignore | ||
| LICENSE | ||
| README.md | ||
| validate_ansible.sh | ||
Ansible Validation Script
A Bash script for validating and checking Ansible playbooks, inventory files, and Jinja2 templates. This script helps ensure the correctness of your Ansible configurations by performing syntax checks, linting, and inventory validation.
Features
- Syntax Validation:
- Validates YAML syntax for playbooks, roles, and variable files.
- Checks inventory files for correctness using
ansible-inventory. - Validates Jinja2 templates for syntax errors.
- Linting:
- Runs
ansible-lintfor YAML files. - Uses
yamllintfor additional YAML checks.
- Runs
- Modes of Operation:
- Default: Checks only files changed in the current Git repository.
--all: Checks all YAML, inventory, and template files in the directory.- Selective modes: Check specific file types with
--playbooks,--inventory, or--template.
Installation
- Clone the repository or copy the script to your desired location.
- Ensure the following dependencies are installed:
ansibleansible-lintyamllintpython3with thejinja2module
- Make the script executable:
chmod +x validate_ansible.sh
Usage
Run the script with the desired options:
./validate_ansible.sh [OPTIONS]
Options
--all: Check all file types (playbooks, inventory, and templates).--playbooks: Check only playbook files.--inventory: Check only inventory files.--template: Check only Jinja2 template files.--help: Display usage information.
If no options are provided, the script will check only files changed in the current Git repository.
Examples
-
Check all files in the directory:
./validate_ansible.sh --all -
Check only playbook files:
./validate_ansible.sh --playbooks -
Validate files changed in the current Git repository:
./validate_ansible.sh
Dependencies
The script requires the following tools and libraries:
- Ansible: For playbook and inventory validation.
- ansible-lint: For linting YAML files.
- yamllint: For additional YAML syntax checks.
- Python 3 with the
jinja2module: For validating Jinja2 templates.
Install missing dependencies using your package manager or pip:
sudo apt install ansible ansible-lint yamllint python3
pip3 install jinja2
Contributing
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with a clear description of your changes.
License
This project is licensed under the AGPL-3.0 License. See the LICENSE file for details.