Member-only story

Ansible troubleshooting — VARIABLE IS NOT DEFINED! ansible_hostname

Root cause analysis when the variable is not misspelled or not defined using the ansible_hostname internal variable and gather_facts boolean.

Luca Berton
3 min readMar 9, 2022

Today we’re going to talk about Ansible troubleshooting, specifically about VARIABLE IS NOT DEFINED! Message.

Most of the time the root cause is a misspelled variable or a variable really not defined. This use case is special about the `ansible_hostname` internal variable.

I’m Luca Berton and welcome to today’s episode of Ansible Pilot.

demo

The best way of talking about Ansible troubleshooting is to jump in a live demo to show you practically the VARIABLE IS NOT DEFINED! and how to solve it!

error code

---
- name: hostname demo
hosts: all
gather_facts: false
tasks:
- name: print hostname
ansible.builtin.debug:
var: ansible_hostname

error execution

ansible-pilot $ ansible-playbook -i virtualmachines/demo/inventory troubleshooting/variablenotdefined_error.yml

--

--

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