简体   繁体   中英

How to encrypt the password over jenkins script url using ansible playbook

I am trying to encrypt the password over jenkins script url using below command, I am able to do it successfully.

Generating a CRUMB token is prerequisite for this, which i achieved it.

URL:

http://localhost:8080/script

script to encrypt:

println(hudson.util.Secret.fromString('password').getEncryptedValue())

Now, I am trying to achieve the same using ansible playbook uri module, i am not able to do it. Can someone please help

curl -d "script=println(hudson.util.Secret.fromString('password').getEncryptedValue())" -v --user admin:<token-ID-for-user-admin> -H "$CRUMB" http://localhost:8080/scriptText

Note: I do not want to use command module in ansible to achieve this task

Please help.

This worked for me, though admittedly I disabled CSRF Protection so am not using a crumb

  tasks:
    - uri:
        url: "http://localhost:8080/scriptText"
        method: POST
        user: "{{ user }}"
        password: "{{ password }}"
        force_basic_auth: yes
        headers: "{{ crumb }}"
        body_format: form-urlencoded
        body: "script=println(hudson.util.Secret.fromString('{{ password_string }}').getEncryptedValue())"
        return_content: yes
      register: result

    - debug:
        var: result.content | trim

The trim filter is used to remove the trailing new line from the result

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM