Ansible - regex help

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 :

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

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

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

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

Cheers,

  -vlado

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

Amazing. These solutions worked! Thank you!!