How to pass parameters to ansible uri module?

user6826691

I'm trying to do this in 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

I'm not sure how to pass these values to uri module, using 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 }}"
Taylor Reece

Referencing https://docs.ansible.com/ansible/latest/modules/uri_module.html for my answer.

For the first thing newTokenName=adminToken, you're looking for the body argument:

body:
  newTokenName: adminToken

It looks like you're passing in basic auth for the credentials, so you're probably looking for the url_username and url_password arguments for the uri module:

url_username: "{{ jenkins_admin_username }}"
url_password: "{{ jenkins_admin_password }}"

Putting all that together, something like this should work:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related