JP Vossen on 5 Jul 2016 16:10:47 -0700

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PLUG] Server date in Ansible/J2?

I have what seems to be a simple question that I can't find on the web. How do I get the current date from the Ansible server into a J2 variable? I know how to do it with {{ }} but that's from the remote node at the time Ansible collected facts (which could be cached), NOT now on the server I'm running on.

It should go without saying that I want the date in the only sane format (ISO-8601): CCYY-MM-DD.

I found one "solution" that was a filter that shelled out and ran the `date` command, but that's just amazingly wrong and bad. Python knows what time it is, so does Ansible, and so does J2. do I get them to cough it up?

Use case (this works, but it's remote node "setup" (get facts) time, not local server "now" time):
  - name: Update image_release file
      line='{{ }} {{ image_release }}'

There's got to be some way that's so fundamentally simple no one even bothers to document it because it's so obvious...except to me.

--  -------------------------------------------------------------------
JP Vossen, CISSP | |
Philadelphia Linux Users Group         --
Announcements -
General Discussion  --