Error saying "One or more undefined variables: 'ansible_facts' is undefined"

0 votes

I have this command that lists all the ansible facts:

ansible localhost -m setup

and it listed all the facts of my system. But when I tried to filter them out, i ended up getting the following error:

ansible localhost -a "echo {{ ansible_facts.ansible_date_time.date }}"
localhost | FAILED => One or more undefined variables: 'ansible_facts' is undefined

Why is this happening when the fact or variable already exists?

Jan 16 in Ansible by Lara
766 views

1 answer to this question.

0 votes

The command you've executed basically means run the setup against the localhost and hence gives you the output but when you run the echo command, it doesnt run the above command and hence has nothing to echo. 

You can create a play book that runs the setup command and stores the facts somewhere and then you can easily echo it.

The playbook would look something like this:

- hosts: localhost
  tasks:
      - debug: var=ansible_date_time

      - debug: msg="the current date is {{ ansible_date_time.date }}"
answered Jan 16 by Karen

Related Questions In Ansible

0 votes
1 answer

Error: One or more undefined variables: 'unicode object' has no attribute 'repo'

Hey change this in your role with_items: apt_repos By ...READ MORE

answered Mar 14 in Ansible by Haseeb
410 views
0 votes
1 answer
+1 vote
1 answer
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
250 views
0 votes
1 answer
0 votes
2 answers