How to escape specific character

347 views
Skip to first unread message

ystk hmsk

unread,
May 13, 2021, 4:06:06 AM5/13/21
to Ansible Project
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

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

4. 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?

Dick Visser

unread,
May 13, 2021, 5:18:52 AM5/13/21
to ansible...@googlegroups.com
what does "it failed" mean?

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

is the install.rsp file OK?
> --
> 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 ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2ed855a4-14ec-48a1-b741-e4f4c2f55cfen%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

ystk hmsk

unread,
May 13, 2021, 6:05:57 AM5/13/21
to Ansible Project
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:

Stefan Hornburg (Racke)

unread,
May 13, 2021, 6:30:49 AM5/13/21
to ansible...@googlegroups.com
On 5/13/21 12:05 PM, ystk hmsk wrote:
> 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

Regards
Racke
> <https://groups.google.com/d/msgid/ansible-project/2ed855a4-14ec-48a1-b741-e4f4c2f55cfen%40googlegroups.com>.
>
>
>
> --
> Dick Visser
> Trust & Identity Service Operations Manager
> GÉANT
>
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/e0e1f712-da67-4fcc-b156-ef9b82a7ad77n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/e0e1f712-da67-4fcc-b156-ef9b82a7ad77n%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

OpenPGP_signature

Brian Coca

unread,
May 13, 2021, 9:36:54 AM5/13/21
to Ansible Project
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



--
----------
Brian Coca

ystk hmsk

unread,
May 13, 2021, 4:28:03 PM5/13/21
to Ansible Project
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:

ystk hmsk

unread,
May 13, 2021, 4:30:37 PM5/13/21
to Ansible Project
Thanx! Brian !

I'll try it!
2021年5月13日木曜日 22:36:54 UTC+9 Brian Coca:

ystk hmsk

unread,
May 14, 2021, 4:38:41 AM5/14/21
to Ansible Project
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:

ystk hmsk

unread,
May 20, 2021, 10:52:56 PM5/20/21
to Ansible Project
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$%@#)
---
- hosts: test
  tasks:
    - win_command: "c:\\ora_binary\\setup.exe -silent -noconfig -responseFile C:\\Work\\db_install.rsp oracle.install.OracleHomeUserPassword={{ oracle_home_user_password }}

2. run Workflow on AnsibleTower  : This was error
  In this case, when setup.exe command ran, Oracle installer said,
  unknown env parameter: %@#

  I guess that Ansible process passed the setup command line to Oracle installer
    "c:\\ora_binary\\setup.exe -silent -noconfig -responseFile C:\\Work\\db_install.rsp oracle.install.OracleHomeUserPassword= Password12"   + "$%@#"
   
Is there someting wrong with me?
2021年5月14日金曜日 17:38:41 UTC+9 ystk hmsk:
Reply all
Reply to author
Forward
0 new messages