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
On Tuesday, November 19, 2019 at 6:50:04 PM UTC, Michael wrote:
>
> 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 :
>
> =============================================
> - name: UnInstall Oracle
> hosts: localhost
> tags: oracle
> become: yes
> become_method: sudo
>
> tasks:
> - name: Generate Response File for Uninstall
> command: /bin/sh -c "/opt/oracle/product/12.1.0/deinstall/deinstall
> -silent -checkonly"
> register: result
> become: true
> become_user: orclient
> become_method: sudo
>
> - name: Set Response Variable - respfile
> set_fact:
> respfile: "{{ result.stdout | regex_search(regexp,'\\1') }}"
> vars:
> regexp: 'Location of response file generated...([^"]+rsp)'
>
> # - name: Debug
> # debug:
> # var: respfile
>
> - name: Uninstall old oracle client
> command: /bin/sh -c "/opt/oracle/product/12.1.0/deinstall/deinstall
> -silent -paramfile {{ respfile }}"
> become: true
> become_user: orclient
> become_method: sudo
>
> =============================================
>
> My debug task when run prints as follows:
>
> TASK [Debug]
> ***************************************************************************************************************
> ok: [localhost] => {
> "respfile": [
>
> "/tmp/deinstall2019-11-19_11-29-40AM/response/deinstall_OraClient12Home1.rsp"
> ]
> }
>
>
> And my uninstall task fails with error message:
>
>
> fatal: [localhost]: FAILED! => {"changed": true, "cmd":
> "/opt/oracle/product/12.1.0/deinstall/deinstall -silent -paramfile
> [u'/tmp/deinstall2019-11-19_11-35-44AM/response/deinstall_OraClient12Home1.rsp']",
>
>
>
> The error shows added characters to the response file path and that causes
> it to fail.
>
> How can i make the response file appear without the added characters?
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/00f6c981-2d50-4d12-856e-56ee748d1579%40googlegroups.com.