JP Vossen on 15 Jul 2016 19:35:31 -0700 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: [PLUG] Server date in Ansible/J2? |
I just noticed I forgot to close this out. Doug, thanks, I tried that but now I forget if it worked. :-/I ended up going with this "solution" which works, but is inefficient and ugly:
image_date: "{{ lookup('pipe','date +%Y-%m-%d') }}"That's basically the one I mentioned below, and I think it sucks, but I've wasted far more time on this than it really deserves, so I'm calling it.
On 07/05/2016 08:04 PM, Doug Stewart wrote:
Try the register: command with a "connection: local" argument, perhaps? That will run only on the execution node. -- Doug StewartOn Jul 5, 2016, at 7:10 PM, JP Vossen <jp@jpsdomain.org> 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 {{ 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.
Later, 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