# Shell command not working

**URL:** <https://forum.ansible.com/t/shell-command-not-working/35715>\
**Category:** Ansible Project\
**Created:** [September 8, 2021, 1:09pm UTC](https://forum.ansible.com/t/shell-command-not-working/35715 "2021-09-08T13:09:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aman\_kumar\_chagti](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@aman\_kumar\_chagti](https://forum.ansible.com/u/aman_kumar_chagti)\
**Post date:** [September 8, 2021, 1:09pm UTC](https://forum.ansible.com/t/shell-command-not-working/35715/1 "2021-09-08T13:09:15Z")

</div>

I’m using the below playbook but it’s giving me an error  
the playbook is

---

<div class="post-metadata">

**Author:** ![Antony\_Stone](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Antony\_Stone](https://forum.ansible.com/u/Antony_Stone)\
**Post date:** [September 8, 2021, 1:15pm UTC](https://forum.ansible.com/t/shell-command-not-working/35715/2 "2021-09-08T13:15:24Z")

</div>

I would suggest you need to escape those inner quotation marks:

&nbsp;&nbsp;"$(dpkg-query -W -f=\"\${binary:Package  
&nbsp;&nbsp;...  
&nbsp;&nbsp;source:Version}\n\")"

Antony.

---

<div class="post-metadata">

**Author:** ![Luca\_remix\_tj\_Lorenz](https://avatars.discourse-cdn.com/v4/letter/l/ea666f/32.png) [@Luca\_remix\_tj\_Lorenz](https://forum.ansible.com/u/Luca_remix_tj_Lorenz)\
**Post date:** [September 8, 2021, 1:18pm UTC](https://forum.ansible.com/t/shell-command-not-working/35715/3 "2021-09-08T13:18:20Z")

</div>

Hello,

> I'm using the below playbook but it's giving me an error  
> the playbook is
> 
> ---  
> - hosts: localhost  
> &nbsp;&nbsp;ignore\_errors: yes  
> &nbsp;&nbsp;become: yes
> 
> &nbsp;&nbsp;tasks:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;- name: Run Vuls Scans  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: curl -X POST -H "Content-Type: text/plain" -H "X-Vuls-OS-Family: `lsb_release -si | awk '{print tolower($1)}'`" -H "X-Vuls-OS-Release: `lsb_release -sr | awk '{print $1}'`" -H "X-Vuls-Kernel-Release: `uname -r`" -H "X-Vuls-Server-Name: `hostname`" --data-binary "$(dpkg-query -W -f="\${binary:Package},\${db:Status-Abbrev},\${Version},\${Source},\${source:Version}\n")" [https://abc.com/vuls](https://abc.com/vuls) \> /path/to/report.json
> 
> But, it's giving me the following error:
> 
> ERROR! 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.  
> &nbsp;&nbsp;mapping values are not allowed in this context
> 
> The error appears to be in '/etc/ansible/vuls.yml': line 9, column 43, but may  
> be elsewhere in the file depending on the exact syntax problem.
> 
> The offending line appears to be:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;- name: Run Vuls Scans  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: curl -X POST -H "Content-Type: text/plain" -H "X-Vuls-OS-Family: `lsb_release -si | awk '{print tolower($1)}'`" -H "X-Vuls-OS-Release: `lsb_release -sr | awk '{print $1}'`" -H "X-Vuls-Kernel-Release: `uname -r`" -H "X-Vuls-Server-Name: `hostname`" --data-binary "$(dpkg-query -W -f="\${binary:Package},\${db:Status-Abbrev},\${Version},\${Source},\${source:Version}\n")" [https://abc.com/vuls](https://abc.com/vuls) \> /path/to/report.json  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^ here

Looks like your shell command is too complex and without enough  
escapes to be treated as yaml in this way, you may write the parameter  
for shell module it in this way:

- name: Run Vuls Scans  
&nbsp;&nbsp;shell: \>  
&nbsp;&nbsp;&nbsp;&nbsp;curl -X POST -H "Content-Type: text/plain" -H "X-Vuls-OS-Family:  
`lsb_release -si | awk '{print tolower($1)}'`" -H "X-Vuls-OS-Release:  
`lsb_release -sr | awk '{print $1}'`" -H "X-Vuls-Kernel-Release:  
`uname -r`" -H "X-Vuls-Server-Name: `hostname`" --data-binary  
"$(dpkg-query -W  
-f="\${binary:Package},\${db:Status-Abbrev},\${Version},\${Source},\${source:Version}\n")"  
[https://abc.com/vuls](https://abc.com/vuls) \> /path/to/report.json

Look at "yaml block scalars"

Anyway i'd prefer to use internal ansible functionalities (uri module  
instead of curl, facts instead of commands to retrieve informations,  
filters instead of awk), instead of raw commands

Luca
