Member-only story

Troubleshooting the “FATAL Template Error while Templating String” in Ansible

How to reproduce, troubleshoot, and fix the ”FATAL template error while templating string” Ansible runtime error.

Luca Berton
4 min readDec 17, 2023

Introduction

Welcome to another episode of Ansible Pilot! I’m Luca Berton, and today we’ll be diving into Ansible troubleshooting, focusing on the “FATAL template error while templating string” runtime error. Join me as we explore how to reproduce, troubleshoot, and fix this challenging issue.

The Demo

Let’s jump straight into a live demo to understand the error practically. In this example, we have a playbook (template_error_string_error.yml) attempting to create an empty file with a variable referencing ~/example.txt.

# template_error_string_error.yml
---
- name: File module demo
hosts: all
vars:
myfile: "{{ ~/example.txt }}"
tasks:
- name: Creating an empty file
ansible.builtin.file:
path: "{{ myfile }}"
state: touch

Executing this playbook (ansible-playbook -i inventory template_error_string_error.yml) results in a fatal error:

--

--

Luca Berton
Luca Berton

Written by Luca Berton

I help creative Automation DevOps, Cloud Engineer, System Administrator, and IT Professional to succeed with Ansible Technology to automate more things everyday

No responses yet