https://github.com/naimetti/ansible-template-validator
A helper script to use with the validate option from ansible template module
https://github.com/naimetti/ansible-template-validator
ansible python-script
Last synced: 3 months ago
JSON representation
A helper script to use with the validate option from ansible template module
- Host: GitHub
- URL: https://github.com/naimetti/ansible-template-validator
- Owner: naimetti
- License: mit
- Created: 2019-11-23T14:52:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-25T23:36:31.000Z (over 6 years ago)
- Last Synced: 2025-08-28T17:00:30.786Z (6 months ago)
- Topics: ansible, python-script
- Language: Python
- Size: 13.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ansible-config-validator
[](https://pypi.org/project/ansible-template-validator/)
[](https://travis-ci.org/naimetti/ansible-template-validator)
A helper script to use with the validate option from ansible
[template](https://docs.ansible.com/ansible/latest/modules/template_module.html) module
The module provides a command line tool to validate configuration templates in cases where the validation depends
on more than one file, and there is no clear way to sandboxing the validation process.
So, for example, if you want to validate an *NGINX* config file that contains a server block configuration you will have
to validate the entire configuration tree of *NGINX* files, therefore what this script does is to replace
the original config file with the new one, runs the validation command, and then restores all to the previous state
independently of the validation command result.
# Install
```shell script
pip install ansible-config-validator
```
# Usage
```shell
usage: ansible-template-validator [-h] [-l SYMLINK]
new_file original_file validation_command
Command to be used as helper with ansible template validate. Replaces
original_file with new_file, and then run validation_command. After this,
returns validation_command return code and original_file is restored.If a
symlink is specified, in case it doesn't exists, it is created pointing to
original_file and then is deleted.
positional arguments:
new_file File used to replace original_file
original_file Original file that is going to be validated
validation_command Command to be executed to validate the config files
optional arguments:
-h, --help show this help message and exit
-l SYMLINK, --create-sym-link SYMLINK
Creates an ephemeral symbolic link pointing to
original_file, just in case it doesn't exists.
```
# Example
```yaml
- name: Update nginx {{website_config}} file
template:
src: "website.conf"
dest: "{{website_config}}"
validate: "ansible-template-validator %s {{website_config}} {{nginx_validation_command|quote}}"
vars:
website_config: "/etc/nginx/sites-enabled/website.conf"
nginx_validation_command: /usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
```
**Note**: _The script must have been previously installed on the target node._