Oddly enough, it seems it the first instance of a space that is the trouble since the error from Ansible reads like this:
FAILED! => {“reason”: "We were unable to read either as JSON nor YAML, these are the errors we got from each:\nJSON: No JSON object could be decoded\n\nSyntax Error while loading YAML.\n mapping values are not allowed in this context\n\nThe error appears to be in roles/image-transfer/tasks/processFile.yml’: line 27, column 136, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n- name: post to db\n command: curl --request POST “myURL/api/v2/write?org=myOrg&bucket=myBucket&precision=ms” --header “Authorization: Token myToken " --data-binary “imageTransfer,source={{ ansible_facts.hostname }},fileName={{ item }} processStart={{ startTime.stdout }},processEnd={{ endTime.stdout }} {{ endTime.stdout }}”\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - “{{ foo }}”\n”}
Thoughts anyone? I have spent two days trying to find a work around and I’m out of ideas.
Solved: While I’d still like to know from al learning perspective what the issue was with the curl format, I have a working task thanks to the suggestion of using the uri module. I posted the working version here for anyone else who finds themselves in my position.
- name: post to db
uri:
url: http://xxx.xx.xx.xx:8086/api/v2/write?org=Demo&bucket=Dimensioner&precision=ms
method: POST
headers:
Authorization: Token xxx.xx.xx.xx
body: imageTransfer,source={{ ansible_facts.hostname }},fileName={{ item }} processStart={{ startTime.stdout }},processEnd={{ endTime.stdout }} {{ endTime.stdout }}
body_format: raw
status_code: 204