# splitting mangled var by delimeter

**URL:** <https://forum.ansible.com/t/splitting-mangled-var-by-delimeter/27891>\
**Category:** Ansible Project\
**Created:** [June 27, 2018, 10:45pm UTC](https://forum.ansible.com/t/splitting-mangled-var-by-delimeter/27891 "2018-06-27T22:45:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [June 27, 2018, 10:45pm UTC](https://forum.ansible.com/t/splitting-mangled-var-by-delimeter/27891/1 "2018-06-27T22:45:52Z")

</div>

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”  
}

`

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [June 27, 2018, 10:57pm UTC](https://forum.ansible.com/t/splitting-mangled-var-by-delimeter/27891/2 "2018-06-27T22:57:56Z")

</div>

`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.`

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [June 28, 2018, 3:49pm UTC](https://forum.ansible.com/t/splitting-mangled-var-by-delimeter/27891/3 "2018-06-28T15:49:11Z")

</div>

anyone? I know I can do it via bash easily enough, but I prefer not to use shell with ansible if possible:

`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 28, 2018, 4:16pm UTC](https://forum.ansible.com/t/splitting-mangled-var-by-delimeter/27891/4 "2018-06-28T16:16:06Z")

</div>

> 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 }}"  
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;&nbsp;&nbsp;- name: date  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: 'date --date="next week" +%B\ %d\,\ %Y'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;changed\_when: false  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: mydate
> 
> &nbsp;&nbsp;&nbsp;&nbsp;- debug:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: mydate.stdout\_lines
> 
> &nbsp;&nbsp;&nbsp;&nbsp;- debug:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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') }}

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [June 28, 2018, 4:24pm UTC](https://forum.ansible.com/t/splitting-mangled-var-by-delimeter/27891/5 "2018-06-28T16:24:16Z")

</div>

Doh! Thx Kai. I like your lookup of the date better than the one I found previously.
