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 {{ ansible_date_time.date }} 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. Just...how 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
    lineinfile:
      dest=..../image_release
      state=present
      insertbefore=BOF
      line='{{ ansible_date_time.date }} {{ 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.

Thanks,
JP
--  -------------------------------------------------------------------
JP Vossen, CISSP | http://www.jpsdomain.org/ | http://bashcookbook.com/
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug