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
> On 12/12/2022 5:37 PM CET Vladimir Botka <[email protected]> wrote: > > > On Mon, 12 Dec 2022 15:30:07 +0100 (CET) > dulhaver via Ansible Project <[email protected]> wrote: > > > I want to automate a list of command exections with at. > > What is the concepts here to specify something like '16:00 2023-01-19'? > > For example, to schedule a command at "2022-12-12 17:30:00" declare > the variables > > 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('%Y-%m-%d %H:%M:%S'))).seconds }}" > at_minutes: "{{ (at_seconds|int / 60)|int + 1 }}" > > gives > > now_datetime: 2022-12-12 17:26:23 > at_datetime: 2022-12-12 17:30:00 > at_seconds: 217 > at_minutes: 4 > > Use the variable *at_minutes* > > - ansible.posix.at: > command: date > /tmp/test_at > count: "{{ at_minutes }}" > units: minutes > - command: at -l > register: out > - debug: > var: out.stdout > > will display the queue > > out.stdout: "5\tMon Dec 12 17:30:00 2022 a admin" > > The command executed as expected > > shell> cat /tmp/test_at > Mon 12 Dec 2022 05:30:00 PM CET > > Example of a complete playbook for testing > > - hosts: localhost > > vars: > > 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('%Y-%m-%d %H:%M:%S'))).seconds }}" > at_minutes: "{{ (at_seconds|int / > 60)|int + 1 }}" > > tasks: > > - debug: > msg: | > now_datetime: {{ now_datetime }} > at_datetime: {{ at_datetime }} > at_seconds: {{ at_seconds }} > at_minutes: {{ at_minutes }} > > - ansible.posix.at: > command: date > /tmp/test_at > count: "{{ at_minutes }}" > units: minutes > > - command: at -l > register: out > > - debug: > var: out.stdout > > -- > 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/20221212173718.597130f3%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/471839507.1031492.1670919820411%40office.mailbox.org.
