dynamic json syntax issue

23 views
Skip to first unread message

Phill Pafford

unread,
Jul 14, 2015, 12:32:25 PM7/14/15
to ansible...@googlegroups.com
I'm trying to dynamically create the JSON response needed for my REST request, I can hard code the JSON var and it works but when I add a variable it fails.


- name: add ssh key to stash via api
uri:
url: "{{stash_api_url}}"
user: "{{stash_username}}"
password: "{{stash_password}}"
force_basic_auth: yes
method: POST
body: '''{"text":"{{stash_ansible_ssh_key_contents.stdout}}"}'''
body_format: json
status_code: 201,409
HEADER_Content-Type: "application/json"
register: ssh_key_added_to_stash
when: stash_ansible_ssh_key_contents.stdout != -1

tried:
- body: '{"text":"{{stash_ansible_ssh_key_contents.stdout}}"}'
- body: ''{"text":"{{stash_ansible_ssh_key_contents.stdout}}"}''
- body: '''{"text":"{{stash_ansible_ssh_key_contents.stdout}}"}'''

if I reverse the single and double quotes there is still an issue

Phill Pafford

unread,
Jul 14, 2015, 12:33:30 PM7/14/15
to ansible...@googlegroups.com
Hardcoding this works:

{
  "text": "my value here"
Reply all
Reply to author
Forward
0 new messages