date time

35 views
Skip to first unread message

Marcel de Vries

unread,
Jul 22, 2022, 6:35:11 AM7/22/22
to Ansible Project

---
- hosts: localhost
  tasks:
    - debug:
        var: hostvars['localhost']['ansible_date_time']['iso8601']


ok: [localhost] => {
    "hostvars['localhost']['ansible_date_time']['iso8601']": "2022-07-22T10:28:46Z"

However:
---
- hosts: localhost
  tasks:
    - debug:
         var:  hostvars['localhost']['ansible_date_time']['iso8601']
      register: date_time
    - debug:
         msg: "{{ ( (date_time).total_seconds() / 3600 ) | int }}"

does not work.
This is because the difference in variable:
 "2022-07-22T10:28:46Z" must be  2022-07-22T10:28:46Z without quotes.
How can I do that?

Dick Visser

unread,
Jul 22, 2022, 7:14:16 AM7/22/22
to ansible...@googlegroups.com
On Fri, 22 Jul 2022 at 12:35, Marcel de Vries
<marcel.mar...@gmail.com> wrote:
>
>
> ---
> - hosts: localhost
> tasks:
> - debug:
> var: hostvars['localhost']['ansible_date_time']['iso8601']
>
>
> ok: [localhost] => {
> "hostvars['localhost']['ansible_date_time']['iso8601']": "2022-07-22T10:28:46Z"
>
> However:
> ---
> - hosts: localhost
> tasks:
> - debug:
> var: hostvars['localhost']['ansible_date_time']['iso8601']
> register: date_time
> - debug:
> msg: "{{ ( (date_time).total_seconds() / 3600 ) | int }}"
>
> does not work.

What do you mean by "does not work"?
What do you expect to happen?
I.e. what are you trying to do/calculate?

If you need the number of second since epoch, then that is already
available as ansible_date_time.epoch_int


> This is because the difference in variable:
> "2022-07-22T10:28:46Z" must be 2022-07-22T10:28:46Z without quotes.

If

> How can I do that?
>
> --
> 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-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/aa5b4d61-d541-4d15-8c33-96c8aa0bb794n%40googlegroups.com.

Marcel de Vries

unread,
Jul 22, 2022, 7:47:50 AM7/22/22
to Ansible Project
I want to compare two date times and get the difference in seconds.

Op vrijdag 22 juli 2022 om 13:14:16 UTC+2 schreef dnmv...@gmail.com:
Reply all
Reply to author
Forward
0 new messages