Shell command not working

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

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

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

Antony.

Hello,

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

---
- hosts: localhost
  ignore_errors: yes
  become: yes

  tasks:

    - name: Run Vuls Scans
      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 > /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.
  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:

    - name: Run Vuls Scans
      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 > /path/to/report.json
                                          ^ 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
  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 > /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