Discussion:
[ansible-project] dynamic json syntax issue
Phill Pafford
2015-07-14 16:32:24 UTC
Permalink
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
--
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+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/38a00239-26f8-4d65-9d65-06085f4cf59d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Phill Pafford
2015-07-14 16:33:30 UTC
Permalink
Hardcoding this works:

{
"text": "my value here"
}
Post by Phill Pafford
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
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
- 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
--
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+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/06295d5d-4ca1-410b-90cc-fd1a7c30a6cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...