<p>When I have a look at your posted output and compare it to mine, there is something wrong:</p>
<pre><code>ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;357&quot;
}
</code></pre>
<p>That output comes from the debug message. But only with <code>debug msg={{ value }}</code> and not with <code>debug var={{ value }}</code>. When I do it with var= then I get (in my case) <code>&quot;32&quot;: &quot;32&quot;</code> as a response.</p>
<p>But that's not the problem. The problem is:</p>
<pre><code>- name: Show diff variable
  debug:
    var: diff
</code></pre>
<p>The name <code>diff</code> for the variable is somehow reserved. You need to set the diff as Jinja</p>
<pre><code>- name: Show diff variable
  debug:
    var: &quot;{{ diff }}&quot;
</code></pre>
<p>And then I see</p>
<pre><code>ok: [localhost] =&gt; {
    &quot;32&quot;: &quot;32&quot;
}
</code></pre>
<p>When I rename the variable to <code>diffa</code> everything is normal. I can't find any documentation for it.</p>
<pre><code>- name: Show mount of days with dedug module
  set_fact:
    diffa: &quot;{{ (( x2 | to_datetime('%d-%m-%Y')) - ( x1  | to_datetime('%d-%m-%Y'))).days }}&quot;

- name: Show mount of days with dedug module
  debug:
    var: diffa
</code></pre>
<p>output:</p>
<pre><code>TASK [Show mount of days with dedug module] *********************************************
ok: [localhost] =&gt; {
    &quot;diffa&quot;: &quot;32&quot;
}
</code></pre>

CC BY-SA 4.0
2021-01-16T18:37:30.730Z
2021-01-16T18:37:30.730Z
TRW
<p>I play this playbook to get amount of days between two expiration certificates dates:</p>
<pre><code>---
- hosts: localhost
  gather_facts: no
  connection: local

  tasks:

  - name: Save the old date
    shell:
       cmd: &gt;-
           date --date=&quot;$(openssl x509 -noout -dates -in cert1.crt
           | grep 'notAfter' | cut -d= -f2)&quot; --utc +&quot;%d-%m-%Y&quot;
    ignore_errors: true
    args:
       executable: /bin/bash
    register: x1

  - name: Save the new date
    shell:
       cmd: &gt;-
           date --date=&quot;$(openssl x509 -noout -dates -in cert2.crt
           | grep 'notAfter' | cut -d= -f2)&quot; --utc +&quot;%d-%m-%Y&quot;
    ignore_errors: true
    args:
       executable: /bin/bash
    register: x2

  - name: Show mount of days with dedug module
    debug:
      var: &quot;{{ (( x2.stdout | to_datetime('%d-%m-%Y')) - ( x1.stdout  | to_datetime('%d-%m-%Y'))).days }}&quot;

  - set_fact:
       diff: &quot;{{ (( x2.stdout | to_datetime('%d-%m-%Y')) - ( x1.stdout | to_datetime('%d-%m-%Y'))).days }}&quot;

  - name: Show diff variable
    debug:
      var: diff

</code></pre>
<p>The playbook run well and i can show the resultat with debug module (task name: Show mount of days with debug module):</p>
<pre><code>ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;357&quot;
}
</code></pre>
<p>Otherwise the task (Show diff variable) show me a null output:</p>
<pre><code>ok: [localhost] =&gt; {}
</code></pre>
<p>I can't find what is wrong with set_fact , anyone have an idea please ?</p>

CC BY-SA 4.0
2021-01-16T18:11:08.017Z
Don't call openssl directly - use [openssl_certificate_info_module](https://docs.ansible.com/ansible/2.9/modules/openssl_certificate_info_module.html#ansible-collections-community-crypto-x509-certificate-info-module)
TRW
<ansible>
SSL Expiration Date
Med
# SSL Expiration Date

(Asked by: username_0 on 2020-11-23)

I play this playbook to get amount of days between two expiration certificates dates:
---
- hosts: localhost
  gather_facts: no
  connection: local

  tasks:

  - name: Save the old date
    shell:
       cmd: >-
           date --date="$(openssl x509 -noout -dates -in cert1.crt
           | grep 'notAfter' | cut -d= -f2)" --utc +"%d-%m-%Y"
    ignore_errors: true
    args:
       executable: /bin/bash
    register: x1

  - name: Save the new date
    shell:
       cmd: >-
           date --date="$(openssl x509 -noout -dates -in cert2.crt
           | grep 'notAfter' | cut -d= -f2)" --utc +"%d-%m-%Y"
    ignore_errors: true
    args:
       executable: /bin/bash
    register: x2

  - name: Show mount of days with dedug module
    debug:
      var: "{{ (( x2.stdout | to_datetime('%d-%m-%Y')) - ( x1.stdout  | to_datetime('%d-%m-%Y'))).days }}"

  - set_fact:
       diff: "{{ (( x2.stdout | to_datetime('%d-%m-%Y')) - ( x1.stdout | to_datetime('%d-%m-%Y'))).days }}"

  - name: Show diff variable
    debug:
      var: diff


The playbook run well and i can show the resultat with debug module (task name: Show mount of days with debug module):
ok: [localhost] => {
    "msg": "357"
}

Otherwise the task (Show diff variable) show me a null output:
ok: [localhost] => {}

I can't find what is wrong with set_fact , anyone have an idea please ?

**Tags:** ansible

> **Comments:**
> **username_1**: Don't call openssl directly - use [openssl_certificate_info_module](https://docs.ansible.com/ansible/2.9/modules/openssl_certificate_info_module.html#ansible-collections-community-crypto-x509-certificate-info-module)  

---

## 1 answers

### Answer by username_1 on 2021-01-16. Score: 0 | Accepted answer

When I have a look at your posted output and compare it to mine, there is something wrong:
ok: [localhost] => {
    "msg": "357"
}

That output comes from the debug message. But only with debug msg={{ value }} and not with debug var={{ value }}. When I do it with var= then I get (in my case) "32": "32" as a response.
But that's not the problem. The problem is:
- name: Show diff variable
  debug:
    var: diff

The name diff for the variable is somehow reserved. You need to set the diff as Jinja
- name: Show diff variable
  debug:
    var: "{{ diff }}"

And then I see
ok: [localhost] => {
    "32": "32"
}

When I rename the variable to diffa everything is normal. I can't find any documentation for it.
- name: Show mount of days with dedug module
  set_fact:
    diffa: "{{ (( x2 | to_datetime('%d-%m-%Y')) - ( x1  | to_datetime('%d-%m-%Y'))).days }}"

- name: Show mount of days with dedug module
  debug:
    var: diffa

output:
TASK [Show mount of days with dedug module] *********************************************
ok: [localhost] => {
    "diffa": "32"
}


---

