HI team,
I have a below playbook, where it works fine if I enter dates manually in vars. but it fails when passing through register. tried max possibilities.
need your help
- hosts: one
become: true
tasks: - shell: " dsmc query filespace / | tail -n 1 | awk ‘{print$2}’"
register: backup - shell: “date +‘%Y-%m-%d’”
register: today - shell: “date -d ‘{{backup.stdout}}’ +‘%Y-%m-%d’”
register: test - set_fact:
date1: “{{test.stdout}}”
date2: “{{today.stdout}}” - debug:
msg: “{{date1}} and {{date2}}” - template:
src: /home/viraj4/ansible/date.j2
dest: /tmp/date.txt - shell: “cat /tmp/date.txt”
register: date - debug:
msg: “{{ date.stdout }}” - shell: “> /tmp/date.txt”
[viraj4@********* ansible]$ cat /home/viraj4/ansible/date.j2
{{ (date1 - date2).days }}
output:
TASK [debug] ***********************************************************************************************************************************************************
ok: [******************** => {
“msg”: “2019-02-13 and 2019-02-13”
}
Perform task: TASK: template (N)o/(y)es/(c)ontinue: y
Perform task: TASK: template (N)o/(y)es/(c)ontinue: ********************************************************************************************************************
TASK [template] ********************************************************************************************************************************************************
fatal: [***************************]: FAILED! => {“changed”: false, “msg”: “AnsibleError: Unexpected templating type error occurred on ({{ (date1 - date2).days }}\n): unsupported operand type(s) for -: ‘AnsibleUnsafeText’ and ‘AnsibleUnsafeText’”}
to retry, use: --limit @/home/viraj4/ansible/time.retry