Sverma
Sverma

Reputation: 19

How to use curl command in ansible playbook

I have to write same syntax in playook as given in this curl - curl -Is "{{url}}" -H "Cookie: ROUTEID=8d1617097a0a51a9e361709ad3f5254b; isBannerTester=1"|grep -iE 'Set-Cookie:|Location'

I have to write same syntax in playook as given in this curl - curl -Is "{{url}}" -H "Cookie: ROUTEID=8d1617097a0a51a9e361709ad3f5254b; isBannerTester=1"|grep -iE 'Set-Cookie:|Location'

- name: "sanity"
  shell: curl -Is "https://{{ENV_DOMAIN}}/applicationNavigator/" -H "Cookie: ROUTEID=8d1617097a0a51a9e361709ad3f5254b; isBannerTester=1"|grep -iE
  args:
     warn: no
  register: res
- debug:
    var: res

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

The error appears to be in '/mnt/banner/deploy/ansible/sanity_test_update.yml': line 40, column 84, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

    - name: "sanity"
      shell: curl -Is "https://studentconnect.acu.edu.au/BannerAdmin.ws/" -H "Cookie: ROUTEID=8d1617097a0a51a9e361709ad3f5254b; isBannerTester=1"|grep -iE
                                                                                   ^ here
We could be wrong, but this one looks like it might be an issue with
unbalanced quotes. If starting a value with a quote, make sure the
line ends with the same set of quotes. For instance this arbitrary
example:

    foo: "bad" "wolf"

Could be written as:

    foo: '"bad" "wolf"'

Upvotes: 1

Views: 8262

Answers (2)

PV_96
PV_96

Reputation: 11

Try the uri module in ansible.

- name: curlcommand
  uri:
    url: https://studentconnect.acu.edu.au/BannerAdmin.ws/
    headers:
      Cookie: ROUTEID=8d1617097a0a51a9e361709ad3f5254b
      isBannerTester=1

You can even check for specific status codes by giving status code: 200 or whatever code you want.

Upvotes: 1

Vladimir Botka
Vladimir Botka

Reputation: 68074

Try what's suggested foo: '"bad" "wolf"'. Quotation should be escaped, I think.

shell: 'curl -Is \"https://{{ENV_DOMAIN}}/applicationNavigator/\"
             -H \"Cookie: ROUTEID=8d1617097a0a51a9e361709ad3f5254b; isBannerTester=1\"|
        grep -iE'

Upvotes: 0

Related Questions