Basically, I am trying to grab the date 1 week from the date when the playbook is run. If there is a better way to do this besides the below, I am all ears.
I have the following variable/output. I would like to split it on the : delimeter and pull [0] (I just want the date, with nothing following). I can’t seem to get the syntax right.
`
Variable
“{{ ‘%m/%d/%Y’|strftime(ansible_date_time.epoch|int + 604800) }}”
Result
ok: [ansible-rhel7] => {
“07/04/2018”: “0.000867195242815”
}
`
Based on additional testing I have come to the conclusion that I do not know what I am doing.... if the above doesn't make sense, that is probably because I don't understand the output correctly. I just need the date one week from when the playbook is run.
anyone? I know I can do it via bash easily enough, but I prefer not to use shell with ansible if possible:
`
anyone?
There wasn't anything wrong with you previous code, so that might be why.
I know I can do it via bash easily enough, but I prefer not to use
shell with ansible if possible:
---
- hosts: "{{ host }}"
tasks:
- name: date
shell: 'date --date="next week" +%B\ %d\,\ %Y'
changed_when: false
register: mydate
- debug:
var: mydate.stdout_lines
- debug:
var: "{{ '%m/%d/%Y'| strftime(ansible_date_time.epoch|int + 604800) }}"
But now you share all the code and the error is easy to spot.
You need to use msg: and not var: on the last debug.
You can also use {{ lookup('pipe', 'date --date="next week" +%m/%d/%Y') }}
Doh! Thx Kai. I like your lookup of the date better than the one I found previously.