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')}}"
- 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