ansible-template-render

module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2025 License: MIT

README

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

  1. The tool analyzes the specified playbook to find template tasks
  2. It creates a temporary directory with a modified version of the playbook and roles
  3. 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
  4. Ansible is executed with only the render_config tag enabled
  5. 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.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL