# Trouble with quoting variables

**URL:** <https://forum.ansible.com/t/trouble-with-quoting-variables/33306>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [July 2, 2020, 12:05pm UTC](https://forum.ansible.com/t/trouble-with-quoting-variables/33306 "2020-07-02T12:05:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ed\_Greenberg](https://avatars.discourse-cdn.com/v4/letter/e/7ab992/32.png) [@Ed\_Greenberg](https://forum.ansible.com/u/Ed_Greenberg)\
**Post date:** [July 2, 2020, 12:05pm UTC](https://forum.ansible.com/t/trouble-with-quoting-variables/33306/1 "2020-07-02T12:05:13Z")

</div>

I have a shell command with json on it. I need some assistance, please, in quoting it properly.

This is an attempt to execute an aws command-line command. I realize that there are a massive number of aws aws modules, but unfortunately, my **bota** is broken, so I can’t use anything that relies on python making api calls. Upcoming is a project to move to python 3 in the hopes of fixing pythons ability to do api work. So I’m stuck with command line.

My playbook says:

`

- name: add to Github Enterprise Security Group  
shell: aws ec2 authorize-security-group-ingress --group-name GithubHappy --ip-permissions ‘[{“IpProtocol”: “tcp”,“FromPort”:22,“ToPort”: 22,“IpRanges”: [{“CidrIp”: “{{external}}/32”,“Description”:“{{servername}}”}]}]’

`

and my error reads:

`

RROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:  
JSON: No JSON object could be decoded

Syntax Error while loading YAML.  
mapping values are not allowed in this context

The error appears to be in ‘/usr/local/ansible/playbooks/newserver.yml’: line 28, column 112, but may  
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: add to Github Enterprise Security Group  
shell: aws ec2 authorize-security-group-ingress --group-name GithubHappy --ip-permissions “'[{“IpProtocol”: “tcp”,“FromPort”:22,“ToPort”: 22,“IpRanges”: [{“CidrIp”: “{{external}}/32”,“Description”:”{{servername}}“}]}]'”  
^ here  
We could be wrong, but this one looks like it might be an issue with  
missing quotes. Always quote template expression brackets when they  
start a value. For instance:

with\_items:

- {{ foo }}

Should be written as:

with\_items:

- “{{ foo }}”

`

I’ve tried quoting the entire thing with both single quotes and then with double quotes, escaping the embedded quotes with backslashes. I’ve tried putting quotes in jinja curlies. such as {{ ‘"’ }} . Just about every permutation I can think of.

Is this even possible? Should I put the aws command in a shell script and run that? Inquiring minds want to know 🙂  
Thanks.

Ed Greenberg

---

<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:** [July 2, 2020, 1:21pm UTC](https://forum.ansible.com/t/trouble-with-quoting-variables/33306/2 "2020-07-02T13:21:12Z")

</div>

What does the correct version of the command line look like?

The docs seem to indicate a slightly different data structure, where  
only IpRanges is added as a json list:  
[https://docs.aws.amazon.com/cli/latest/reference/ec2/authorize-security-group-ingress.html](https://docs.aws.amazon.com/cli/latest/reference/ec2/authorize-security-group-ingress.html)

I would try defining the data structure as a variable in your playbook  
(as YAML, which is easier to read/write), and then combine to\_json and  
quote.
