ansible playbook with curl

1,861 views
Skip to first unread message

Shankar Bala

unread,
Apr 12, 2017, 5:27:43 PM4/12/17
to Ansible Project
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 ?

Matt Martz

unread,
Apr 12, 2017, 5:35:27 PM4/12/17
to ansible...@googlegroups.com
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 }}"

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7f33367e-f6a5-44c7-8f5b-2374f481522f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Dick Visser

unread,
Apr 12, 2017, 5:37:50 PM4/12/17
to ansible...@googlegroups.com
On 12 April 2017 at 23:34, Matt Martz <ma...@sivel.net> wrote:
> Why not just use the `uri` module?


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


--
Dick Visser
Sr. System & Network Engineer
GÉANT

Want to join us? We're hiring: https://www.geant.org/jobs
Reply all
Reply to author
Forward
0 new messages