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 17, 2019 in Ansible by Lara
4,161 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 17, 2019 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, 2019 in Ansible by Haseeb
3,055 views
0 votes
1 answer
+1 vote
1 answer
+15 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,439 views
+2 votes
1 answer
0 votes
2 answers
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP