# How to escape specific character

**URL:** <https://forum.ansible.com/t/how-to-escape-specific-character/35165>\
**Category:** Ansible Project\
**Created:** [May 13, 2021, 8:06am UTC](https://forum.ansible.com/t/how-to-escape-specific-character/35165 "2021-05-13T08:06:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ystk\_hmsk](https://avatars.discourse-cdn.com/v4/letter/y/45deac/32.png) [@ystk\_hmsk](https://forum.ansible.com/u/ystk_hmsk)\
**Post date:** [May 13, 2021, 8:06am UTC](https://forum.ansible.com/t/how-to-escape-specific-character/35165/1 "2021-05-13T08:06:05Z")

</div>

I’m using ansible tower.  
And I made workflow to install Oracle on the virtual server.

The way to install oracle is …

1. copy Oracle installer.exe file to the virtual server.

2. make response file(install.rsp.j2 jinjer2 template) on the virtual server.  
install.rsp includes below

OracleHomeUserPassword={{ oracle\_home\_user\_password }}

and oracle\_home\_user\_password is passed from inventory

1. make install command bat file(run.bat.j2 jinjer2 template) on the virtual server.  
run.bat is below  
setup.exe -silent -noconfig -waitforcompletion -nowait -responseFile C:\Work\db\_install.rsp

2. run.bat on the virtual server.

It always worked, but one day it failed.  
It was because password included specific characters like “$”, “#”,“%” …

I thought that variable oracle\_home\_user\_password in inventory or jinjer2 must be escaped but I don’t know.

I tried these…

1. In install.rsp.j2 ,  
OracleHomeUserPassword={{ oracle\_home\_user\_password | escape }}

2. in install.rsp.j2,  
OracleHomeUserPassword={{ oracle\_home\_user\_password| regex\_escape }}

3. In install.rsp.j2 ,  
OracleHomeUserPassword={{ oracle\_home\_user\_password | escape() }}

4. in install.rsp.j2,  
OracleHomeUserPassword={{ oracle\_home\_user\_password| regex\_escape() }}

They were all failed…(T\_T

Anyone know how to escape specific character in jinjer2 or any other better way?

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 13, 2021, 9:18am UTC](https://forum.ansible.com/t/how-to-escape-specific-character/35165/2 "2021-05-13T09:18:23Z")

</div>

what does "it failed" mean?

- ansible run fails?  
- ansible runs OK but batch file fails?  
- ??

is the install.rsp file OK?

---

<div class="post-metadata">

**Author:** ![ystk\_hmsk](https://avatars.discourse-cdn.com/v4/letter/y/45deac/32.png) [@ystk\_hmsk](https://forum.ansible.com/u/ystk_hmsk)\
**Post date:** [May 13, 2021, 10:05am UTC](https://forum.ansible.com/t/how-to-escape-specific-character/35165/3 "2021-05-13T10:05:56Z")

</div>

Hi, dick  
Thanks for reply.

I’m sorry, I might be wrong.  
I checked the ansible job message again, and it was oracle error.  
The parameter “OracleHomeUserPassword” and variable was in install.rsp file made by ansible.  
But when specific character “#” in the password was passed to the setup.exe of oracle installer, it failure.

So, I wrote , adding double quate to install.rsp.j2 like below.  
And I’ll try.  
oracleHomeUserPassword=“{{ oracle\_home\_user\_password| escape() }}” # double quate

or  
oracleHomeUserPassword=“”{{ oracle\_home\_user\_password| escape() }}“” # double quate x2

or  
oracleHomeUserPassword=‘{{ oracle\_home\_user\_password| escape() }}’ # single quate

or  
oracleHomeUserPassword=‘’{{ oracle\_home\_user\_password| escape() }}‘’ # single quate x2

or other.

It’ll take for a little time.  
I’ll share the result later.

Thanx

2021年5月13日木曜日 18:18:52 UTC+9 [dick....@geant.org](mailto:dick....@geant.org):

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [May 13, 2021, 10:30am UTC](https://forum.ansible.com/t/how-to-escape-specific-character/35165/4 "2021-05-13T10:30:26Z")

</div>

> Hi, dick  
> Thanks for reply.
> 
> I'm sorry, I might be wrong.  
> I checked the ansible job message again, and it was oracle error.  
> The parameter "OracleHomeUserPassword" and variable was in install.rsp file made by ansible.  
> But when specific character "#" in the password was passed to the setup.exe of oracle installer, it failure.
> 
> So, I wrote , adding double quate to install.rsp.j2 like below.  
> And I'll try.  
> oracleHomeUserPassword="{{ oracle\_home\_user\_password| escape() }}" # double quate  
> or  
> oracleHomeUserPassword=""{{ oracle\_home\_user\_password| escape() }}"" # double quate x2  
> or  
> oracleHomeUserPassword='{{ oracle\_home\_user\_password| escape() }}' # single quate  
> or  
> oracleHomeUserPassword=''{{ oracle\_home\_user\_password| escape() }}'' # single quate x2  
> or other.
> 
> It'll take for a little time.  
> I'll share the result later.

So this is only related to Ansible when you know how the specific characters are supposed to  
escaped in the configuration file.

The escape filter is meant to apply to HTML strings:  
[https://jinja.palletsprojects.com/en/3.0.x/templates/#jinja-filters.escape](https://jinja.palletsprojects.com/en/3.0.x/templates/#jinja-filters.escape)

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

> Thanx
> 
> 2021年5月13日木曜日 18:18:52 UTC+9 dick....@geant.org:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;what does "it failed" mean?
> 
> &nbsp;&nbsp;&nbsp;&nbsp;- ansible run fails?  
> &nbsp;&nbsp;&nbsp;&nbsp;- ansible runs OK but batch file fails?  
> &nbsp;&nbsp;&nbsp;&nbsp;- ??
> 
> &nbsp;&nbsp;&nbsp;&nbsp;is the install.rsp file OK?
> 
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> I'm using ansible tower.  
> &nbsp;&nbsp;&nbsp;&nbsp;\> And I made workflow to install Oracle on the virtual server.  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> The way to install oracle is ...  
> &nbsp;&nbsp;&nbsp;&nbsp;\> 1. copy Oracle installer.exe file to the virtual server.  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> 2. make response file(install.rsp.j2 jinjer2 template) on the virtual server.  
> &nbsp;&nbsp;&nbsp;&nbsp;\> install.rsp includes below  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> OracleHomeUserPassword={{ oracle\_home\_user\_password }}  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> and oracle\_home\_user\_password is passed from inventory  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> 3. make install command bat file(run.bat.j2 jinjer2 template) on the virtual server.  
> &nbsp;&nbsp;&nbsp;&nbsp;\> run.bat is below  
> &nbsp;&nbsp;&nbsp;&nbsp;\> setup.exe -silent -noconfig -waitforcompletion -nowait -responseFile C:\Work\db\_install.rsp  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> 4. run.bat on the virtual server.  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> It always worked, but one day it failed.  
> &nbsp;&nbsp;&nbsp;&nbsp;\> It was because password included specific characters like "$", "#","%" ....  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> I thought that variable oracle\_home\_user\_password in inventory or

jinjer2 must be escaped but I don't know.

> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> I tried these...  
> &nbsp;&nbsp;&nbsp;&nbsp;\> 1) In install.rsp.j2 ,  
> &nbsp;&nbsp;&nbsp;&nbsp;\> OracleHomeUserPassword={{ oracle\_home\_user\_password | escape }}  
> &nbsp;&nbsp;&nbsp;&nbsp;\> 2) in install.rsp.j2,  
> &nbsp;&nbsp;&nbsp;&nbsp;\> OracleHomeUserPassword={{ oracle\_home\_user\_password| regex\_escape }}  
> &nbsp;&nbsp;&nbsp;&nbsp;\> 3) In install.rsp.j2 ,  
> &nbsp;&nbsp;&nbsp;&nbsp;\> OracleHomeUserPassword={{ oracle\_home\_user\_password | escape() }}  
> &nbsp;&nbsp;&nbsp;&nbsp;\> 4) in install.rsp.j2,  
> &nbsp;&nbsp;&nbsp;&nbsp;\> OracleHomeUserPassword={{ oracle\_home\_user\_password| regex\_escape() }}  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> They were all failed.......(T\_T  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> Anyone know how to escape specific character in jinjer2 or any other better way?  
> &nbsp;&nbsp;&nbsp;&nbsp;\>  
> &nbsp;&nbsp;&nbsp;&nbsp;\> --  
> &nbsp;&nbsp;&nbsp;&nbsp;\> You received this message because you are subscribed to the Google Groups "Ansible Project" group.  
> &nbsp;&nbsp;&nbsp;&nbsp;\> To unsubscribe from this group and stop receiving emails from it,

send an email to ansible-proje...@googlegroups.com.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 13, 2021, 1:36pm UTC](https://forum.ansible.com/t/how-to-escape-specific-character/35165/5 "2021-05-13T13:36:09Z")

</div>

Aside from escaping for shells (use `quote` filter), you might want to  
mark the password as 'unsafe for templating':

oracle\_home\_user\_password: !unsafe @#$lksWHATEVER{{wontgettemplated

---

<div class="post-metadata">

**Author:** ![ystk\_hmsk](https://avatars.discourse-cdn.com/v4/letter/y/45deac/32.png) [@ystk\_hmsk](https://forum.ansible.com/u/ystk_hmsk)\
**Post date:** [May 13, 2021, 8:28pm UTC](https://forum.ansible.com/t/how-to-escape-specific-character/35165/6 "2021-05-13T20:28:03Z")

</div>

Morning!  
Thanx for the reply and nice information brae!

It hasn’t worked yet, so I’ll refer.

My workflow is from oracle installer copy to install,  
so each execution takes a very long time.

I’ll cut out the process from workflow and I’ll try.

2021年5月13日木曜日 19:30:49 UTC+9 [brae...@gmail.com](mailto:brae...@gmail.com):

---

<div class="post-metadata">

**Author:** ![ystk\_hmsk](https://avatars.discourse-cdn.com/v4/letter/y/45deac/32.png) [@ystk\_hmsk](https://forum.ansible.com/u/ystk_hmsk)\
**Post date:** [May 13, 2021, 8:30pm UTC](https://forum.ansible.com/t/how-to-escape-specific-character/35165/7 "2021-05-13T20:30:37Z")

</div>

Thanx! Brian !

I’ll try it!

2021年5月13日木曜日 22:36:54 UTC+9 Brian Coca:

---

<div class="post-metadata">

**Author:** ![ystk\_hmsk](https://avatars.discourse-cdn.com/v4/letter/y/45deac/32.png) [@ystk\_hmsk](https://forum.ansible.com/u/ystk_hmsk)\
**Post date:** [May 14, 2021, 8:38am UTC](https://forum.ansible.com/t/how-to-escape-specific-character/35165/8 "2021-05-14T08:38:41Z")

</div>

I tried many times today,but I couldn’t complete.

Ummm, I’m thinking other patterns.

2021年5月14日金曜日 5:30:37 UTC+9 ystk hmsk:

---

<div class="post-metadata">

**Author:** ![ystk\_hmsk](https://avatars.discourse-cdn.com/v4/letter/y/45deac/32.png) [@ystk\_hmsk](https://forum.ansible.com/u/ystk_hmsk)\
**Post date:** [May 21, 2021, 2:52am UTC](https://forum.ansible.com/t/how-to-escape-specific-character/35165/9 "2021-05-21T02:52:55Z")

</div>

Hi.

I’ve been trying various patterns that I got adviced above.  
But it couldn’t work well.

Although this system uses jinjar2 template,  
I tried simple playbook and workflow.  
And I found below.

1. run ansible-playbook : This was OK  
Playbook.yaml is below (oracle\_home\_user\_password=Password123$%@#)
