如何将参数传递给ansible uri模块?
How to pass parameters to ansible uri module?
我正尝试在 ansible 中执行此操作
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
将这些值传递给 uri 模块
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 }}"
我的回答参考了 https://docs.ansible.com/ansible/latest/modules/uri_module.html。
首先 newTokenName=adminToken
,您要查找 body
参数:
body:
newTokenName: adminToken
看起来您正在为凭据传递基本身份验证,因此您可能正在寻找 uri
模块的 url_username
和 url_password
参数:
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 }}"
我正尝试在 ansible 中执行此操作
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 }}"
我的回答参考了 https://docs.ansible.com/ansible/latest/modules/uri_module.html。
首先 newTokenName=adminToken
,您要查找 body
参数:
body:
newTokenName: adminToken
看起来您正在为凭据传递基本身份验证,因此您可能正在寻找 uri
模块的 url_username
和 url_password
参数:
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 }}"