Hello everyone,
My registered vars are not working with my math equation using to_datetime filter it will work with the string “2019-04-01” but not with my var.
`
PLAY [localhost] *********************************************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [localhost]
TASK [get the file] ******************************************************************************************************************************************
changed: [localhost]
TASK [debug] *************************************************************************************************************************************************
ok: [localhost] => {
“today”: {
“changed”: true,
“cmd”: “du -h --time /etc/ansible/ansible.cfg | grep -Eo ‘[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}’”,
“delta”: “0:00:00.011270”,
“end”: “2019-05-01 09:27:11.662919”,
“failed”: false,
“rc”: 0,
“start”: “2019-05-01 09:27:11.651649”,
“stderr”: “”,
“stderr_lines”: ,
“stdout”: “2019-04-30”,
“stdout_lines”: [
“2019-04-30”
]
}
}
TASK [get current date] **************************************************************************************************************************************
changed: [localhost]
TASK [debug] *************************************************************************************************************************************************
ok: [localhost] => {
“current”: {
“changed”: true,
“cmd”: “date +%F”,
“delta”: “0:00:00.010083”,
“end”: “2019-05-01 09:27:12.031688”,
“failed”: false,
“rc”: 0,
“start”: “2019-05-01 09:27:12.021605”,
“stderr”: “”,
“stderr_lines”: ,
“stdout”: “2019-05-01”,
“stdout_lines”: [
“2019-05-01”
]
}
}
TASK [debug] *************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {“msg”: “the field ‘args’ has an invalid value ({u’msg’: u"{{ ( ‘current’ | to_datetime(‘%Y-%m-%d’) - ‘today’ | to_datetime(‘%Y-%m-%d’) ).days }}"}), and could not be converted to an dict.The error was: time data ‘current’ does not match format ‘%Y-%m-%d’\n\nThe error appears to have been in ‘/etc/ansible/wipstat.yml’: line 20, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - debug:\n ^ here\n”}
PLAY RECAP ***************************************************************************************************************************************************
localhost : ok=5 changed=2 unreachable=0 failed=1
`