Doug Stewart on 5 Jul 2016 17:04:46 -0700

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

Re: [PLUG] Server date in Ansible/J2?

Try the register: command with a "connection: local" argument, perhaps? That will run only on the execution node. 
Doug Stewart

> On Jul 5, 2016, at 7:10 PM, JP Vossen <> wrote:
> 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
>    lineinfile:
>      dest=..../image_release
>      state=present
>      insertbefore=BOF
>      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.
> Thanks,
> JP
> --  -------------------------------------------------------------------
> JP Vossen, CISSP | |
> ___________________________________________________________________________
> Philadelphia Linux Users Group         --
> Announcements -
> General Discussion  --
Philadelphia Linux Users Group         --
Announcements -
General Discussion  --