Ansible date / time variables not found

1,603 views
Skip to first unread message

Andrew Cholakian

unread,
May 29, 2014, 11:52:25 AM5/29/14
to ansible...@googlegroups.com
I've got a particularly vexing bug wrt the date / time helpers. Running the following:

- debug: "var=ansible_date_time['year']"

Does not give me the current year, the variable remains uninterpolated. I've tried various permutations of quoting, to no avail. The debug output suspiciously drops a leading [, making me think there's a bug in the ansible internals when parsing this. Here's the debug output:

 _________________________________________________________
< TASK: tower-backup | debug var=ansible_date_time'year'] >
 ---------------------------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


    "ansible_date_time[year]": "{{ ansible_date_time[year] }}",
    "item": ""
}

Matt Martz

unread,
May 29, 2014, 11:57:39 AM5/29/14
to ansible...@googlegroups.com, Andrew Cholakian
You probably need to change your debug task to look like 1 of the three examples:

    - debug: var=ansible_date_time.year

    - debug:
        var: ansible_date_time['year']

    - debug:
        var: ansible_date_time.year

-- 
Matt Martz
ma...@sivel.net
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d59a51c9-d40c-4063-88a3-3b0235258ba7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Peters

unread,
May 29, 2014, 1:12:54 PM5/29/14
to ansible...@googlegroups.com
Just to clarify, this is because the "[" is part of YAML and is not
getting parsed as you're expecting. You could probably also just quote
the whole line.
> https://groups.google.com/d/msgid/ansible-project/etPan.538758ec.643c9869.4b11%40mobiletuvix.rackspace.corp.

Michael DeHaan

unread,
May 29, 2014, 1:20:35 PM5/29/14
to ansible...@googlegroups.com
All of the above should work, I'd have to play around with it to see what's going on but it does seem like there's some quote mangling in the debug module that may need to be fixxored.

--Michael




Andrew Cholakian

unread,
May 29, 2014, 1:55:31 PM5/29/14
to ansible...@googlegroups.com
Thanks for the quick response Michael! For some reason the whole line I was actually using it in now works. Maybe I had missed a quote or something, but the bracket syntax now works. I don't know why I didn't see that in a full hour of staring at it yesterday, but it works now *shrugs*


--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/uEIeOwVFv8w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages