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.

Attachment: pgp4WQz0aegz5.pgp
Description: OpenPGP digital signature

Reply via email to