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
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/e7de6afb-5349-4c11-814a-1ac382581e87%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.