That works! Even with looping
##################################################################
- hosts: localhost
tasks:
- ansible.posix.at:
command: date > /tmp/test_at
count: "{{ at_datetime|at_minutes }}"
units: minutes
vars:
at_datetime: "{{ item }}"
loop:
- "2022-12-13 12:09"
- "2022-12-13 12:10"
- "2022-12-13 12:13"
##################################################################
would it be worth a PR on the issue or is this too quick'n'dirty?
It seems to be a different approach then the one suggested in the PR though (I
can not judge on any of that due to missing python skills).
> On 12/13/2022 11:03 AM CET Vladimir Botka <[email protected]> wrote:
>
>
> On Tue, 13 Dec 2022 09:23:40 +0100 (CET)
> dulhaver via Ansible Project <[email protected]> wrote:
>
> > thx that really works. It is not really user-friendly though.
> >
> > Apparently I am not the only one thinking this should be easier, so there
> > is an issue for adding a more intuitive way to specify time and date
> > https://github.com/ansible-collections/ansible.posix/issues/326
>
> > > now_datetime: "{{ '%Y-%m-%d %H:%M:%S'|strftime }}"
> > > at_datetime: "2022-12-12 17:30:00"
> > > at_seconds: "{{ ((at_datetime|to_datetime) -
> > > (now_datetime|to_datetime)).seconds }}"
> > > at_minutes: "{{ (at_seconds|int / 60)|int + 1 }}"
> > >
> > > - ansible.posix.at:
> > > command: date > /tmp/test_at
> > > count: "{{ at_minutes }}"
> > > units: minutes
>
> Yes, it's rather awkward. I simplified the declaration of
> *at_seconds*. It might be a good idea to have a conversion function
> for this, e.g.
>
>
> - ansible.posix.at:
> command: date > /tmp/test_at
> count: "{{ at_datetime|at_minutes }}"
> units: minutes
> vars:
> at_datetime: "2022-12-12 17:30:00"
>
>
> Try
>
> shell> cat plugins/filter/at_minutes.py
> from datetime import datetime
>
>
> def at_minutes(at_datetime):
> timesince = datetime.fromisoformat(at_datetime) - datetime.now()
> return int(timesince.total_seconds() / 60 + 1)
>
>
> class FilterModule(object):
>
> def filters(self):
> return {
> 'at_minutes': at_minutes,
> }
>
>
> --
> Vladimir Botka
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/20221213110300.52f9ca3e%40gmail.com.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/1586929021.1050941.1670932154662%40office.mailbox.org.