Ansible date / time variables not found

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:

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

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.

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

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