ansible-template-render
A tool for rendering Ansible template files locally without applying changes to remote hosts.
Overview
ansible-template-render allows you to preview configuration files that would be generated by Ansible playbooks without actually deploying them to the target servers. This is useful for verifying configuration templates before deployment.
Features
- Generate configuration files from Ansible templates locally
- Process playbooks with dependencies
- Respect variable precedence in Ansible
- Render templates with the same variable context that would be used in actual deployment
- Option to generate files without executing Ansible
Installation
$ go install github.com/zinrai/ansible-template-render@latest
Or build it manually:
$ go build -o ansible-template-render cmd/main.go
Usage
Create a config file (e.g., config.yml):
playbooks:
- name: myplaybook
inventory: inventory
Then run:
$ ansible-template-render -config config.yml
Command-line options
Usage: ansible-template-render --config [config file]
-config string Config file path
-version Show version
-generate-only Generate modified Ansible files without executing
-log-level string Log level (debug, info, warn, error) (default "info")
How It Works
- The tool analyzes the specified playbook to find template tasks
- It creates a temporary directory with a modified version of the playbook and roles
- Template tasks are modified to:
- Add
delegate_to: localhost and run_once: true
- Add a
render_config tag
- Redirect output to the local
output directory
- Ansible is executed with only the
render_config tag enabled
- The resulting files are generated in the
output directory
Configuration File
The configuration file uses YAML format:
playbooks:
- name: playbook1
inventory: hosts
- name: playbook2
inventory: other_hosts
options:
ansible_args: "-v --diff" # Additional arguments for ansible-playbook
Examples
Basic usage:
$ ansible-template-render -config config.yml
Generate only without executing:
$ ansible-template-render -config config.yml -generate-only
Verbose logging:
$ ansible-template-render -config config.yml -log-level debug
License
This project is licensed under the MIT License.