ansible playbook with curl

Hi All

I am trying to run ansible playbook to create powerdns record .pdns.yml

  • name: add dns record
    vars:
    pilot_dns: “{{ input_dns }}”
    pilot_dom: “{{ input_domain }}”
    arecord: “{{ input_hostname }}”
    iprecord: “{{ input_ip }}”
    command: curl -X PATCH --data ‘{“rrsets”: [ {“name”: "’" {{ arecord }} “.'”, “type”: “A”, “ttl”: 86400, “changetype”: “REPLACE”, “records”: [ {“content”: “'” {{ iprecord }} “'”, “disabled”: false } ] } ] }’ -H “‘X-API-Key: changeme’” ‘http://“{{ pilot_pdns }}”:8081/api/v1/servers/localhost/zones/“{{ pilot_dom }}”.’ | jq .
    tags: add_pdns

I get syntax error when i run as “ansible-playbook pdns.yml --check”

ERROR! Syntax Error while loading YAML.

The offending line appears to be:

iprecord: “{{ input_ip }}”
command: curl -X PATCH --data ‘{“rrsets”: [ {“name”: "’" {{ arecord }} “.'”, “type”: “A”, “ttl”: 86400, “changetype”: “REPLACE”, “records”: [ {“content”: “'” {{ iprecord }} “'”, “disabled”: false } ] } ] }’ -H “‘X-API-Key: changeme’” ‘http://“{{ pilot_pdns }}”:8081/api/v1/servers/localhost/zones/“{{ pilot_dom }}”.’ | jq .
^ here

any help here ?

Why not just use the uri module?

The following should be equivalent:

  • uri:
    method: PATCH
    url: “http://{{ pilot_pdns }}:8081/api/v1/servers/localhost/zones/{{ pilot_dom }}”
    body:
    rrsets:
  • name: “{{ arecord }}”
    type: A
    ttl: 86400
    changetype: REPLACE
    records:
  • content: “{{ iprecord }}”
    disabled: false
    body_format: json
    headers:
    ‘X-API-Key’: changeme
    return_content: yes
    register: whatever
    tags:
  • add_pdns
    vars:
    pilot_dns: “{{ input_dns }}”
    pilot_dom: “{{ input_domain }}”
    arecord: “{{ input_hostname }}”
    iprecord: “{{ input_ip }}”

Or even more tailored for this job:
https://github.com/Nosmoht/ansible-module-powerdns#records