【发布时间】:2020-10-14 02:49:25
【问题描述】:
我在 jenkins 中使用凭证插件在正文中使用私钥创建用户的角色存在问题。 我可以得到面包屑,但是当我请求创建凭证时,我得到了无效的面包屑错误。
我的角色:
- name: Get Jenkins Crumb
uri:
url: "{{ master_url }}/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)"
user: '{{ master_username }}'
password: "my_token"
method: GET
return_content: yes
force_basic_auth: yes
body_format: form-urlencoded
register: crumb
- debug:
msg: "{{ crumb.content.split(':')[1]}}"
- name: Add credential to Node
uri:
url: "{{ master_url }}/credentials/store/system/domain/_/createCredentials"
user: "{{ master_username }}"
password: "my_token"
method: POST
status_code: 302
body_format: form-urlencoded
headers:
Jenkins-Crumb: "{{ crumb.content.split(':')[1]}}"
Cookie: "{{ crumb.set_cookie }}"
body: |
json={
"": "0",
"credentials": {
"scope": "GLOBAL",
"id": "jenkins_linux_slave1_auth",
"username": "jenkins",
"password": "jenkins",
"privateKeySource": {
"stapler-class": "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource",
"privateKey": "{{ private_key_file['content'] | b64decode | to_json}}"
},
"description": "Jenkins Linux Slave1 Authentication",
"stapler-class": "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey"
}
}
输出\错误:
TASK [jenkins : Get Jenkins Crumb] *********************************************
ok: [protheus]
TASK [jenkins : debug] *********************************************************
ok: [protheus] => {
"msg": "f87df3f83a7ecfb5f5b2e7af0c0beb218dd239ec460fba832ff36f0a90e42287"
}
TASK [jenkins : Add credential to Node] ****************************************
fatal: [protheus]: FAILED! => {"cache_control": "must-revalidate,no-cache,no-store", "changed": false, "connection": "close", "content": "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n<title>Error 403 No valid crumb was included in the request</title>\n</head>\n<body><h2>HTTP ERROR 403 No valid crumb was included in the request</h2>\n<table>\n<tr><th>URI:</th><td>/credentials/store/system/domain/_/createCredentials</td></tr>\n<tr><th>STATUS:</th><td>403</td></tr>\n<tr><th>MESSAGE:</th><td>No valid crumb was included in the request</td></tr>\n<tr><th>SERVLET:</th><td>Stapler</td></tr>\n</table>\n<hr><a href=\"http://eclipse.org/jetty\">Powered by Jetty:// 9.4.27.v20200227</a><hr/>\n\n</body>\n</html>\n", "content_length": "593", "content_type": "text/html;charset=iso-8859-1", "elapsed": 0, "msg": "Status code was 403 and not [302]: HTTP Error 403: Forbidden", "redirected": false, "server": "Jetty(9.4.27.v20200227)", "status": 403, "url": "http://192.168.0.120:9080/credentials/store/system/domain/_/createCredentials", "x_content_type_options": "nosniff"}
PLAY RECAP *********************************************************************
protheus : ok=9 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Ansible 未能成功完成。任何错误输出应该是 上面可见。请修正这些错误,然后重试。
有谁知道怎么回事?
谢谢!
【问题讨论】:
标签: json jenkins ansible roles credentials