Python

ansible uri 用正文中的空格替換 + 符號或 jenkins api 替換它,誰有問題?

  • January 23, 2018

我正在使用 jenkins api 通過 ansible 創建憑據。

- name: Add credential to add node
 uri:
     body: |
         json={
             "": "0",
             "credentials": {
               "scope": "GLOBAL",
               "id": "jenkins_linux_slave1_auth",
               "username": "jenkins",
               "password": "123456",
               "privateKeySource": {
                 "stapler-class": "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource",
                 "privateKey": "-----BEGIN RSA PRIVATE KEY-----\nProc-Type: 4,ENCRYPTED\nPRIVATE+KEY+WITH+PLUS+SIGN\n-----END RSA PRIVATE KEY-----"
               },
               "description": "Jenkins Linux Slave1 Authentication",
               "stapler-class": "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey"
             }
           }
     force_basic_auth: yes
     method: POST
     password: "{{ jenkins_user_token }}"
     status_code: 302
     url: "{{ jenkins_url }}/credentials/store/system/domain/_/createCredentials"
     user: "{{ jenkins_user }}"
     validate_certs: no
 tags:
     - credential

這會在詹金斯中創建憑據,但是當我在詹金斯中檢查私鑰時,它會替換+**(space)**

[![Replace + with Space](https://i.stack.imgur.com/pruQS.png)](https://i.stack.imgur.com/pruQS.png)

The Jenkins API accepts normal URL encoded form data, but usually with only one field, named json`.

The Ansible uri module does not URL encode the body when sending normal URL encoded form data. You need to do this yourself.`

引用自:https://serverfault.com/questions/893776