# Passing a '(' in a variable string

**URL:** <https://forum.ansible.com/t/passing-a-in-a-variable-string/31498>\
**Category:** Ansible Project\
**Created:** [October 21, 2019, 4:34pm UTC](https://forum.ansible.com/t/passing-a-in-a-variable-string/31498 "2019-10-21T16:34:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Feyrer](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@Stephen\_Feyrer](https://forum.ansible.com/u/Stephen_Feyrer)\
**Post date:** [October 21, 2019, 4:34pm UTC](https://forum.ansible.com/t/passing-a-in-a-variable-string/31498/1 "2019-10-21T16:34:22Z")

</div>

Hi there,

I have a password vault and a script to which I am passing a password.

The vault looks kind of like this:

`

---

<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:** [October 21, 2019, 5:51pm UTC](https://forum.ansible.com/t/passing-a-in-a-variable-string/31498/2 "2019-10-21T17:51:35Z")

</div>

Use "quote" filter  
[https://docs.ansible.com/ansible/devel/user\_guide/playbooks\_filters.html#id8](https://docs.ansible.com/ansible/devel/user_guide/playbooks_filters.html#id8)

&nbsp;&nbsp;&nbsp;&nbsp;- name: my-script  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;script: My-Script.ps1 -secret {{ vault\_password|quote }}

Cheers,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Stephen\_Feyrer](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@Stephen\_Feyrer](https://forum.ansible.com/u/Stephen_Feyrer)\
**Post date:** [October 23, 2019, 7:24am UTC](https://forum.ansible.com/t/passing-a-in-a-variable-string/31498/3 "2019-10-23T07:24:26Z")

</div>

Hi Vlado,

Apologies for the delayed reply. Unfortunately, that hasn’t worked. In the documentation that you linked to, that syntax is described in connection with the shell operator rather than the script.

I tried this:

`

- name: my-script  
script: My-Script.ps1 -secret {{ vault\_password | quote }}

`

and

`

- name: my-script  
script: My-Script.ps1 -secret {{ vault\_password | join(“”) }}

`

Both produced the same result as before.

Thank you.

---

<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:** [October 23, 2019, 8:07am UTC](https://forum.ansible.com/t/passing-a-in-a-variable-string/31498/4 "2019-10-23T08:07:18Z")

</div>

Hi Stephen,

> \> \> vault\_password: abc(123  
> \> \> tasks:  
> \> \> - name: my-script  
> \> \> script: My-Script.ps1 -secret {{ vault\_password }}  
> \> \>  
> \> \> (Missing closing ')' in expression.:String)   
> \>  
> \> Use "quote" filter  
> \> [https://docs.ansible.com/ansible/devel/user\_guide/playbooks\_filters.html#id8](https://docs.ansible.com/ansible/devel/user_guide/playbooks_filters.html#id8)  
> \>  
> \> - name: my-script  
> \> script: My-Script.ps1 -secret {{ vault\_password|quote }}

> Apologies for the delayed reply. Unfortunately, that hasn't worked. In  
> the documentation that you linked to, that syntax is described in  
> connection with the shell operator rather than the script.
> 
> I tried this:  
> - name: my-script  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;script: My-Script.ps1 -secret {{ vault\_password | quote }}  
> and  
> - name: my-script  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;script: My-Script.ps1 -secret {{ vault\_password | join("") }}  
> Both produced the same result as before.

This is strange. It works for me.

&nbsp;&nbsp;&nbsp;&nbsp;$ cat my-script.sh  
&nbsp;&nbsp;&nbsp;&nbsp;#!/bin/sh  
&nbsp;&nbsp;&nbsp;&nbsp;echo $1  
&nbsp;&nbsp;&nbsp;&nbsp;exit 0  
&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;$ cat play.yml  
&nbsp;&nbsp;&nbsp;&nbsp;- hosts: localhost  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vault\_password: abc(123  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- script: 'my-script.sh {{ vault\_password|quote }}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: result  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: result.stdout  
&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;$ ansible-playbook play.yml  
&nbsp;&nbsp;&nbsp;&nbsp;[...]  
&nbsp;&nbsp;&nbsp;&nbsp;ok: [localhost] =\> {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"result.stdout": "abc(123\n"  
&nbsp;&nbsp;&nbsp;&nbsp;}

Without quoted argument I see this error:

fatal: [localhost]: FAILED! =\> {"changed": true, "msg": "non-zero return  
code", "rc": 2, "stderr": "/bin/sh: 1: Syntax error: \"(\" unexpected\n",  
"stderr\_lines": ["/bin/sh: 1: Syntax error: \"(\" unexpected"], "stdout":  
"", "stdout\_lines": }

Cheers,

&nbsp;&nbsp;-vlado

---

<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:** [October 23, 2019, 8:19am UTC](https://forum.ansible.com/t/passing-a-in-a-variable-string/31498/5 "2019-10-23T08:19:34Z")

</div>

The error "Missing closing ')'..." is very probably reported by the script.  
Find out how to pass the argument to the script from the command-line before  
you proceed with Ansible.

Cheers,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Stephen\_Feyrer](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@Stephen\_Feyrer](https://forum.ansible.com/u/Stephen_Feyrer)\
**Post date:** [October 23, 2019, 8:51am UTC](https://forum.ansible.com/t/passing-a-in-a-variable-string/31498/6 "2019-10-23T08:51:26Z")

</div>

Hi Vlado,

You are right, it is the Powershell parameter interpretation. I have previously tried quoting in the Ansible playbook like:

`

- name: my-script  
script: My-Script.ps1 -svc\_password ‘{{ vault\_password }}’

`

and  
`

- name: my-script  
script: My-Script.ps1 -svc\_password “{{ vault\_password }}”

`

Neither of these worked. Per your suggestion I tried:

`

- name: my-script  
script: My-Script.ps1 -svc\_password {{ ‘vault\_password’ }}

`

This worked, I’ll admit, I’m a little surprised. I have to do some reading on Jinja2.

Thank you!

---

<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:** [October 23, 2019, 9:32am UTC](https://forum.ansible.com/t/passing-a-in-a-variable-string/31498/7 "2019-10-23T09:32:06Z")

</div>

Hi Stephen,

> &nbsp;&nbsp;&nbsp;&nbsp;- name: my-script  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;script: My-Script.ps1 -svc\_password '{{ vault\_password }}'
> 
> and  
> &nbsp;&nbsp;&nbsp;&nbsp;- name: my-script  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;script: My-Script.ps1 -svc\_password "{{ vault\_password }}"

Quoting from \*Gotchas\*: "If your value starts with a quote the entire value  
must be quoted, not just part of it..."  
[https://docs.ansible.com/ansible/latest/reference\_appendices/YAMLSyntax.html#gotchas](https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html#gotchas)

Correct syntax is

&nbsp;&nbsp;&nbsp;&nbsp;- name: my-script  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;script: 'My-Script.ps1 -svc\_password {{ vault\_password }}'

and  
&nbsp;&nbsp;&nbsp;&nbsp;- name: my-script  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;script: "My-Script.ps1 -svc\_password {{ vault\_password }}"

> &nbsp;&nbsp;&nbsp;&nbsp;- name: my-script  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;script: My-Script.ps1 -svc\_password {{ 'vault\_password' }}
> 
> This worked, I'll admit, I'm a little surprised...

I'm surprised too. In my case

&nbsp;&nbsp;&nbsp;&nbsp;- script: my-script.sh {{ 'vault\_password' }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: result

the result was

&nbsp;&nbsp;&nbsp;&nbsp;ok: [localhost] =\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"result.stdout": "vault\_password\n"  
&nbsp;&nbsp;&nbsp;&nbsp;}

Cheers,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Stephen\_Feyrer](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@Stephen\_Feyrer](https://forum.ansible.com/u/Stephen_Feyrer)\
**Post date:** [October 24, 2019, 10:31am UTC](https://forum.ansible.com/t/passing-a-in-a-variable-string/31498/8 "2019-10-24T10:31:42Z")

</div>

Hi Vlado,

That does make more sense. Thank you.
