# Error Lookup Private Key in Post Request

**URL:** <https://forum.ansible.com/t/error-lookup-private-key-in-post-request/33455>\
**Category:** Ansible Developer\
**Created:** [July 21, 2020, 4:04pm UTC](https://forum.ansible.com/t/error-lookup-private-key-in-post-request/33455 "2020-07-21T16:04:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcos\_Roberto\_de\_Ab](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@Marcos\_Roberto\_de\_Ab](https://forum.ansible.com/u/Marcos_Roberto_de_Ab)\
**Post date:** [July 21, 2020, 4:04pm UTC](https://forum.ansible.com/t/error-lookup-private-key-in-post-request/33455/1 "2020-07-21T16:04:57Z")

</div>

I have an error in the post with the uri module.  
I need to create a credential for my Vagrant VM on Jenkins via api.  
In my tests, I realized that the error is in passing the value of the private key, in this line:

privateKey": “{{ lookup(‘file’, ‘…/.vagrant/machines/protheus/virtualbox/private\_key’)}}”

If I pass the value of the private key manually, in just one line the credential is created without errors.

My task:

- name: Get Private Key Value  
debug: msg=“Private Key Value is {{ lookup(‘file’, ‘…/.vagrant/machines/protheus/virtualbox/private\_key’)}}”

- name: Get Jenkins Crumb  
uri:  
url: “{{ master\_url }}/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)”  
user: “{{ master\_username }}”  
password: “{{ master\_password }}”  
force\_basic\_auth: yes  
return\_content: yes  
register: crumb

- name: Create a Jenkins Credential  
uri:  
method: POST  
user: “{{ master\_username }}”  
password: “{{ master\_password }}”  
force\_basic\_auth: yes  
#body\_format: json  
#body\_format: form-urlencoded  
url: “{{ master\_url }}/credentials/store/system/domain/\_/createCredentials”  
headers:  
Jenkins-Crumb: “{{ crumb.content.split(‘:’)[1] }}”  
Cookie: “{{ crumb.set\_cookie }}”  
body: |  
json={  
“credentials”: {  
“scope”: “GLOBAL”,  
“id”: “{{ slave\_linux\_jenkins\_cred\_id }}”,  
“username”: “{{ slave\_linux\_jenkins\_username }}”,  
“privateKeySource”: {  
“stapler-class”: “com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource”,  
“privateKey”: “{{ lookup(‘file’, ‘…/.vagrant/machines/protheus/virtualbox/private\_key’)}}”  
},  
“description”: “Node app-protheus”,  
“stapler-class”: “com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey”  
}  
}  
#status\_code: 302  
validate\_certs: no  
follow\_redirects: yes  
#ignore\_errors: true

Error:

`

TASK [jenkins : Get Private Key Value] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [192.168.0.133] =\> {  
“msg”: “Private Key Value is -----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAKCAQEA1HDltyx+rUOngUQEggu2DRj5luG929fBrFhyUTzNmhTfxuO+\nsZbkqvL5OWb5K3cMsBYH2U3LPeN8ag/ERgI3ktEH2L8aOqdCJROYP74zXJpa68Wx\nXPmfOuEsxTbkYUe65Ga7q8mwRMWLFL8mRS85DijbSkpHrrYaMRPKW/zr6P7ciZL6\nXCcMgReNzZiRCKRFWAE3HT6Pd7+BSBluJIXi52Ey2L+Wx38OdvbrStSJcp83YZc8\nJv9uVEVCeeW3NAN0yF8TL6Gbv1o7zIl1dMhLaNIppGU1wGoLZ2jGHHSKj3/MimmpwtWPAhg3V4dM\nblbo8+3V3Z9AsycAiSD7JyECgYEA2CFJla8GeRMGEujruuIVOF+wIdbI5zssic/s\nei/AFpdE71jQNxhCxgD/hjShcxFp18e8N13LCYjZIwUeUaAmH30Vs1Y9YWCFcIiC\nj/Z9rpHem8/4u6EiLfnF2WOY05XHEtRwpFBR+pzSR8F3rQMF4BhOF0zNP6XWwiay\nerwkCqkCgYEApL/F7ewsl+9MoA9Ys6fL6D2DpfKK8Bl3gWVs/wll9TzF2NfGszEx\nnc7axyEFd99qIYb2wcoB4+yjlEQKGxDzMCAjMjAvpQPJ+GCYqGQpFQPNvv/F49ET\nUHni4DBp3RnIWfsOzrqLpRMeGsB1+pnphhytbFdNirLjgXj6MFMWZB4=\n-----END RSA PRIVATE KEY-----”  
}

TASK [jenkins : Get Jenkins Crumb] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [192.168.0.133]

TASK [jenkins : Create a Jenkins Credential] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[WARNING]: The value True (type bool) in a string field was converted to ‘True’ (type string). If this does not look like what you expect, quote the entire value to ensure it  
does not change.  
fatal: [192.168.0.133]: FAILED! =\> {“cache\_control”: “must-revalidate,no-cache,no-store”, “changed”: false, “connection”: “close”, “content”: “\n\n\<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/\>\nError 400 Nothing is submitted\n\n

## HTTP ERROR 400 Nothing is submitted
\n\n\n\n\n\n

| URI: | /credentials/store/system/domain/\_/createCredentials |
| STATUS: | 400 |
| MESSAGE: | Nothing is submitted |
| SERVLET: | Stapler |

\n
* * *
\<a href="[http://eclipse.org/jetty\](http://eclipse.org/jetty%5C)”\>Powered by Jetty:// 9.4.27.v20200227
* * *
\n\n\n\n", “content\_length”: “527”, “content\_type”: “text/html;charset=iso-8859-1”, “elapsed”: 0, “msg”: “Status code was 400 and not [200]: HTTP Error 400: Bad Request”, “redirected”: false, “server”: “Jetty(9.4.27.v20200227)”, “status”: 400, “url”: “[http://192.168.0.120:9080/credentials/store/system/domain/\_/createCredentials](http://192.168.0.120:9080/credentials/store/system/domain/_/createCredentials)”, “x\_content\_type\_options”: “nosniff”}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
192.168.0.133 : ok=6 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

`

Does anyone know what could be wrong with my task?
