我正在努力做到这一点
curl 'http://localhost:8080/user/admin/descriptorByName/jenkins.security.ApiTokenProperty/generateNewToken' --data 'newTokenName=adminToken' --user '{{ jenkins_admin_username }}:{{ jenkins_admin_password }}' -c cookies.txt
我不确定如何使用ansible 2.9.6
newTokenName = adminToken'--user {{jenkins_admin_username}}:{{ jenkins_admin_password}}
- name: get token
uri:
url: "http://localhost:8080/user/admin/descriptorByName/jenkins.security.ApiTokenProperty/generateNewToken"
method: POST
return_content: yes
body: "newTokenName=adminToken=user={{ jenkins_admin_username }}:{{ jenkins_admin_password }}"
headers:
Cookie: "{{ jenkins_crumb.set_cookie }}"
答案 0 :(得分:1)
请参考https://docs.ansible.com/ansible/latest/modules/uri_module.html。
对于第一件事newTokenName=adminToken
,您正在寻找body
参数:
body:
newTokenName: adminToken
您似乎正在传递基本身份验证的凭据,因此您可能正在寻找url_username
模块的url_password
和uri
参数:
url_username: "{{ jenkins_admin_username }}"
url_password: "{{ jenkins_admin_password }}"
将所有内容放在一起,这样的方法应该起作用:
- name: get token
uri:
url: "http://localhost:8080/user/admin/descriptorByName/jenkins.security.ApiTokenProperty/generateNewToken"
method: POST
return_content: yes
body:
newTokenName: adminToken
url_username: "{{ jenkins_admin_username }}"
url_password: "{{ jenkins_admin_password }}"
headers:
Cookie: "{{ jenkins_crumb.set_cookie }}"