Re: [ansible-project] at - specific time & date

2022-12-13 Thread Vladimir Botka
On Tue, 13 Dec 2022 15:15:06 +0100 (CET)
dulhaver via Ansible Project  wrote:

> > Yes, it's worth PR. I'll write tests for this. The question is which
> > collection?
> 
> 
> honestly, I am still not really 100% sure what the term
> 'collection' actually means in the Ansible context and how things
> are organized. The issue, however, lives in
> ansible-collection/ansible.posix. Isn't that hint enough?

I'm not sure if this kind of datetime conversion belongs to POSIX.

To learn about collections see https://github.com/ansible-collections

For example, Ansible.Posix, where the module ansible.posix.at comes
from, is "Ansible Collection targeting POSIX and POSIX-ish platforms."
https://docs.ansible.com/ansible/latest/collections/ansible/posix/index.html


-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20221213155643.7a48cea6%40gmail.com.


pgpRbwAkotuZb.pgp
Description: OpenPGP digital signature


Re: [ansible-project] at - specific time & date

2022-12-13 Thread dulhaver via Ansible Project
> Yes, it's worth PR. I'll write tests for this. The question is which
> collection?


honestly, I am still not really 100% sure what the term 'collection' actually 
means in the Ansible context and how things are organized. The issue, however, 
lives in ansible-collection/ansible.posix. Isn't that hint enough?



> On 12/13/2022 1:20 PM CET Vladimir Botka  wrote:
> 
>  
> > count: "{{ at_datetime|at_minutes }}"
> > ...
> > would it be worth a PR on the issue or is this too quick'n'dirty? 
> 
> It's quick'n'clean I'd say :)
> 
> Yes, it's worth PR. I'll write tests for this. The question is which
> collection?
> 
> -- 
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/20221213132000.59eb4000%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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1457110830.3856.1670940906516%40office.mailbox.org.


Re: [ansible-project] at - specific time & date

2022-12-13 Thread Vladimir Botka
> count: "{{ at_datetime|at_minutes }}"
> ...
> would it be worth a PR on the issue or is this too quick'n'dirty? 

It's quick'n'clean I'd say :)

Yes, it's worth PR. I'll write tests for this. The question is which
collection?

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20221213132000.59eb4000%40gmail.com.


pgpGVDMiFBB_w.pgp
Description: OpenPGP digital signature


Re: [ansible-project] at - specific time & date

2022-12-13 Thread dulhaver via Ansible Project
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  wrote:
> 
>  
> On Tue, 13 Dec 2022 09:23:40 +0100 (CET)
> dulhaver via Ansible Project  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 ansible-project+unsubscr...@googlegroups.com.
> 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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1586929021.1050941.1670932154662%40office.mailbox.org.


Re: [ansible-project] at - specific time & date

2022-12-13 Thread Vladimir Botka
On Tue, 13 Dec 2022 09:23:40 +0100 (CET)
dulhaver via Ansible Project  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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20221213110300.52f9ca3e%40gmail.com.


pgp4WQz0aegz5.pgp
Description: OpenPGP digital signature


Re: [ansible-project] at - specific time & date

2022-12-13 Thread dulhaver via Ansible Project
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  wrote:
> 
>  
> On Mon, 12 Dec 2022 15:30:07 +0100 (CET)
> dulhaver via Ansible Project  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 ansible-project+unsubscr...@googlegroups.com.
> 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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/471839507.1031492.1670919820411%40office.mailbox.org.


Re: [ansible-project] at - specific time & date

2022-12-12 Thread Vladimir Botka
On Mon, 12 Dec 2022 15:30:07 +0100 (CET)
dulhaver via Ansible Project  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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20221212173718.597130f3%40gmail.com.


pgpzoGGh0CP7_.pgp
Description: OpenPGP digital signature


Re: [ansible-project] at - specific time & date

2022-12-12 Thread Andrew Latham
So you are using ansible.posix.at?

That plugin uses a file to run AT as seen at
https://github.com/ansible-collections/ansible.posix/blob/main/plugins/modules/at.py#L82

So in the code it uses the ```now +``` method. This may be a situation
where a command/shell call would be the solution.





On Mon, Dec 12, 2022 at 7:30 AM dulhaver via Ansible Project <
ansible-project@googlegroups.com> wrote:

> I want to automate a list of command exections with at.
>
> Looking at the at modules documentation I see only unit & count for
> specify the time and date. That looks a litte unprecise to me.
>
> What is the concepts here to specify something like '16:00 2023-01-19'?
>
> --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/1330471356.973684.1670855407841%40office.mailbox.org
> .
>


-- 
- Andrew "lathama" Latham -

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CA%2Bqj4S-c0hytLWqTXerMKKpP%3DK098DHtkm1Yrdq62ZVP_cjhiQ%40mail.gmail.com.


[ansible-project] at - specific time & date

2022-12-12 Thread dulhaver via Ansible Project
I want to automate a list of command exections with at.

Looking at the at modules documentation I see only unit & count for specify the 
time and date. That looks a litte unprecise to me. 

What is the concepts here to specify something like '16:00 2023-01-19'?

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1330471356.973684.1670855407841%40office.mailbox.org.