Ansible get_url 返回 400

问题描述 投票:0回答:1

当使用 Ansible get_url 从 jfrog 下载文件时,它总是返回 400。而使用curl 尝试此操作效果完美。

带有 get_url 的 Ansible 任务不起作用:

    - name: Download file
      ansible.builtin.get_url:
        url: 'https://xxx.jfrog.io/artifactory/xxx-yyy-zzz/file-adsds-1234.somefile_xxx.tgz'
        headers:
          Authorization: 'Bearer {{ artifactory_token }}'
        dest: '/opt/file.tgz'
        mode: '0600'

与curl一起使用的任务:

  - name : Download file
    shell: "curl -L -S -H 'Authorization: Bearer {{ artifactory_token }}' 'https://xxx.jfrog.io/artifactory/xxx-yyy-zzz/file-adsds-1234.somefile_xxx.tgz' --output '/opt/file.tgz'"
    args:
      creates: "/opt/file.tgz"
ansible artifactory jfrog
1个回答
0
投票

一个最小的示例手册

---
- hosts: localhost
  become: false
  gather_facts: false

  vars:

    URL: repository.example.com
    FILE: example.png
    TOKEN: abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz123

  tasks:

  - name: Download from Artifactory
    get_url:
      url: "https://{{ URL }}/artifactory/SHARE/{{ FILE }}"
      headers:
        Authorization: 'Bearer {{ TOKEN }}'
      dest: "/tmp"
      mode: 0600

通过

调用
ansible-playbook bearer.yml -vvvv

将产生

的输出
TASK [Download from Artifactory] **************************************************************
task path: /home/ansible-user/test/bearer.yml:14
changed: [localhost] => changed=true
  checksum_dest: null
  checksum_src: abcdefghijklmnopqrstuvwxyz1234567890abcd
  dest: /tmp/example.png
  elapsed: 0
  gid: 1234567890
  group: users
  invocation:
    module_args:
      attributes: null
      backup: false
      checksum: ''
      ciphers: null
      client_cert: null
      client_key: null
      decompress: true
      dest: /tmp
      force: false
      force_basic_auth: false
      group: null
      headers:
        Authorization: Bearer abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz123
      http_agent: ansible-httpget
      mode: 384
      owner: null
      selevel: null
      serole: null
      setype: null
      seuser: null
      timeout: 10
      tmp_dest: null
      unredirected_headers: []
      unsafe_writes: false
      url: https://repository.example.com/artifactory/SHARE/example.png
      url_password: null
      url_username: null
      use_gssapi: false
      use_netrc: true
      use_proxy: true
      validate_certs: true
  md5sum: abcdefghijklmnopqrstuvwxyz1234567890abcd
  mode: '0600'
  msg: OK (4936 bytes)
  owner: ansible-user
  secontext: unconfined_u:object_r:user_home_t:s0
  size: 4936
  src: /home/ansible-user/.ansible/tmp/ansible-tmp-1234567890.1234567-1234567-123456789012345/tmpabcd1234
  state: file
  status_code: 200
  uid: 1234567890
  url: https://repository.example.com/artifactory/SHARE/example.png

并将下载的文件保留在

ll /tmp/example.png
-rw-------. 1 ansible-user users 4936 Dec 20 08:00 /tmp/example.png

与 CLI 调用相同

curl --silent --location -H 'Authorization: Bearer ${TOKEN}' -O 'https://repository.example.com/artifactory/SHARE/example.png'
© www.soinside.com 2019 - 2024. All rights reserved.