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 ?