# Syntax for running commands with braces in them

**URL:** <https://forum.ansible.com/t/syntax-for-running-commands-with-braces-in-them/21142>\
**Category:** Ansible Project\
**Created:** [April 12, 2016, 3:29pm UTC](https://forum.ansible.com/t/syntax-for-running-commands-with-braces-in-them/21142 "2016-04-12T15:29:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Groten](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@Ryan\_Groten](https://forum.ansible.com/u/Ryan_Groten)\
**Post date:** [April 12, 2016, 3:29pm UTC](https://forum.ansible.com/t/syntax-for-running-commands-with-braces-in-them/21142/1 "2016-04-12T15:29:37Z")

</div>

I am trying to execute a task that runs the following command (which includes a number of quote, brackets, colons, etc):

`  
command: curl -XPUT “[http://localhost:9200/\_cluster/settings](http://localhost:9200/_cluster/settings)” -d’{ “transient” : { “cluster.routing.allocation.enable” : “none” } }’

`

I tried escaping all the quotes and {}, but that doesn’t seem to work.

`  
command: ‘curl -XPUT “[http://localhost:9200/\_cluster/settings](http://localhost:9200/_cluster/settings)” -d'{ “transient” : { “cluster.routing.allocation.enable” : “none” } }’’

`

I also tried treating the whole command as a jinja string (I think?)

`  
command: {{ ‘curl -XPUT “[http://localhost:9200/\_cluster/settings](http://localhost:9200/_cluster/settings)” -d’{ “transient” : { “cluster.routing.allocation.enable” : “none” } }‘’ }}

`

Thanks,  
Ryan

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [April 12, 2016, 3:41pm UTC](https://forum.ansible.com/t/syntax-for-running-commands-with-braces-in-them/21142/2 "2016-04-12T15:41:24Z")

</div>

I know this isn’t really a direct answer to your question, but why not use the `uri` module instead?

- uri:  
url: “[http://localhost:9200/\_cluster/settings](http://localhost:9200/_cluster/settings)”  
method: PUT  
body:  
transient:  
cluster.routing.allocation.enable: “none”  
body\_format: json

---

<div class="post-metadata">

**Author:** ![Ryan\_Groten](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@Ryan\_Groten](https://forum.ansible.com/u/Ryan_Groten)\
**Post date:** [April 12, 2016, 5:02pm UTC](https://forum.ansible.com/t/syntax-for-running-commands-with-braces-in-them/21142/3 "2016-04-12T17:02:54Z")

</div>

Should have known, there’s always a module to do what I want better. Thanks very much I’ll try this out!

---

<div class="post-metadata">

**Author:** ![Merri\_Jensen](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Merri\_Jensen](https://forum.ansible.com/u/Merri_Jensen)\
**Post date:** [April 12, 2016, 6:47pm UTC](https://forum.ansible.com/t/syntax-for-running-commands-with-braces-in-them/21142/4 "2016-04-12T18:47:40Z")

</div>

I ran into this problem too. If you don’t happen to use the ‘uri’ module, it’s the double quotes that need to be escaped, not the curly’s…

command: curl -XPUT “[http://localhost:9200/\_cluster/settings](http://localhost:9200/_cluster/settings)” -d’{ "transient" : { "cluster.routing.allocation.enable" : "none" } }’

You need them for -H’s too.

-H "Content-Type: application/json"

HTH,  
-MJensen

---

<div class="post-metadata">

**Author:** ![Ryan\_Groten](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@Ryan\_Groten](https://forum.ansible.com/u/Ryan_Groten)\
**Post date:** [April 12, 2016, 8:12pm UTC](https://forum.ansible.com/t/syntax-for-running-commands-with-braces-in-them/21142/5 "2016-04-12T20:12:46Z")

</div>

I must be close, but it’s not working with uri module. Here’s what I put in the role. Setting the uri\_body as a fact beforehand and using “to\_json” was an attempt to get around the error I’m getting, but that doesn’t help either.

`

- name: Set uri\_body (workaround)  
set\_fact:  
uri\_body:  
transient:  
cluster.routing.allocation.enable: “none”

- name: Disable shard allocation to prevent es from rebalancing missing shards  
uri:  
url: “[http://localhost:9200/\_cluster/settings](http://localhost:9200/_cluster/settings)”  
method: PUT  
body: “{{ uri\_body | to\_json }}”  
body\_format: json  
`

When I run it I get this:

`fatal: [vm2.example.com]: FAILED! => {"changed": false, "failed": true, "module_stderr": "", "module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible-tmp-1460491268.69-8119459959976/uri\", line 3363, in <module>\r\n main()\r\n File \"/tmp/ansible-tmp-1460491268.69-8119459959976/uri\", line 374, in main\r\n dict_headers['Content-Type'] = 'application/json'\r\nTypeError: 'NoneType' object does not support item assignment\r\n", "msg": "MODULE FAILURE", "parsed": false}`

---

<div class="post-metadata">

**Author:** ![ananta.c](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@ananta.c](https://forum.ansible.com/u/ananta.c)\
**Post date:** [April 13, 2016, 6:44pm UTC](https://forum.ansible.com/t/syntax-for-running-commands-with-braces-in-them/21142/6 "2016-04-13T18:44:18Z")

</div>

I didn’t quite follow the exact issue, but I was able to download a page with {: in file name . Below is my test

[vagrant@admin ansible]$ ansible-playbook -i hosts -u root --tags=url -l admin base.yml

PLAY [base role] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [admin]

TASK: [base | get url with] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [admin] =\> (item=[http://localhost/hello](http://localhost/hello){:.html)

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
admin : ok=2 changed=1 unreachable=0 failed=0

[vagrant@admin ansible]$  
[vagrant@admin ansible]$ cat roles/base/tasks/urltest.yml

- name : get url with  
get\_url: url={{ item }} dest=/tmp  
tags: url  
with\_items:
- [http://localhost/hello](http://localhost/hello){:.html  
[vagrant@admin ansible]$ ls /tmp/hello{:.html  
/tmp/hello{:.html  
[vagrant@admin ansible]$

---

<div class="post-metadata">

**Author:** ![ananta.c](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@ananta.c](https://forum.ansible.com/u/ananta.c)\
**Post date:** [April 13, 2016, 7:13pm UTC](https://forum.ansible.com/t/syntax-for-running-commands-with-braces-in-them/21142/7 "2016-04-13T19:13:46Z")

</div>

never mind. I should have read the whole thread .

---

<div class="post-metadata">

**Author:** ![Ryan\_Groten](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@Ryan\_Groten](https://forum.ansible.com/u/Ryan_Groten)\
**Post date:** [April 14, 2016, 2:26pm UTC](https://forum.ansible.com/t/syntax-for-running-commands-with-braces-in-them/21142/8 "2016-04-14T14:26:51Z")

</div>

Finally got it working, thanks everyone for the suggestions! For reference here’s what ended up working:  
`

- name: Set uri endpoints  
set\_fact:  
es\_disable\_allocation:  
transient:  
cluster.routing.allocation.enable: “none”

- name: Disable shard allocation to prevent es from rebalancing missing shards  
uri:  
url: “[http://localhost:9200/\_cluster/settings](http://localhost:9200/_cluster/settings)”  
method: PUT  
body: “{{ es\_disable\_allocation|to\_json }}”  
`
