# Ansible - regex help

**URL:** <https://forum.ansible.com/t/ansible-regex-help/31686>\
**Category:** Ansible Project\
**Created:** [November 19, 2019, 6:50pm UTC](https://forum.ansible.com/t/ansible-regex-help/31686 "2019-11-19T18:50:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael3](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@Michael3](https://forum.ansible.com/u/Michael3)\
**Post date:** [November 19, 2019, 6:50pm UTC](https://forum.ansible.com/t/ansible-regex-help/31686/1 "2019-11-19T18:50:04Z")

</div>

I’m creating a script that dynamically generates a response file for an uninstall and stores the response file in a var for reuse in the uninstall command. My play :

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [November 19, 2019, 8:25pm UTC](https://forum.ansible.com/t/ansible-regex-help/31686/2 "2019-11-19T20:25:15Z")

</div>

(\<path\> and \<params\> replaced for readability)  
\*respfile\* is a list. It's possible to run the command with the first item

&nbsp;&nbsp;- name: Uninstall old oracle client  
&nbsp;&nbsp;&nbsp;&nbsp;command: /bin/sh -c "\<path\>/deinstall \<params\> {{ respfile.0 }}"

,or in the loop if there might be more items to process

&nbsp;&nbsp;- name: Uninstall old oracle client  
&nbsp;&nbsp;&nbsp;&nbsp;command: /bin/sh -c "\<path\>/deinstall \<params\> {{ item }}"  
&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ respfile }}"

Cheers,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [November 19, 2019, 8:35pm UTC](https://forum.ansible.com/t/ansible-regex-help/31686/3 "2019-11-19T20:35:16Z")

</div>

I think the issue is your respfile fact contains a list, not a string, hence the in the Debug output.

There are a couple of ways to fix that. You can either do it when you are creating the fact (use the ‘first’ filter to just get the first element of the list), like this.

- name: Set Response Variable - respfile  
set\_fact:  
respfile: “{{ result.stdout | regex\_search(regexp,‘\1’) |first}}”

Or you could do it when you use the respfile fact

- name: Uninstall old oracle client  
command: /bin/sh -c “/opt/oracle/product/12.1.0/  
deinstall/deinstall -silent -paramfile {{ respfile|first }}”  
become: true  
become\_user: orclient  
become\_method: sudo

Instead of using a filter you can use array syntax:

- name: Uninstall old oracle client  
command: /bin/sh -c “/opt/oracle/product/12.1.0/  
deinstall/deinstall -silent -paramfile {{ respfile[0] }}”  
become: true  
become\_user: orclient  
become\_method: sudo

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Michael3](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@Michael3](https://forum.ansible.com/u/Michael3)\
**Post date:** [November 20, 2019, 5:15am UTC](https://forum.ansible.com/t/ansible-regex-help/31686/4 "2019-11-20T05:15:11Z")

</div>

Amazing. These solutions worked! Thank you!!
