curl 如何使用Ansible从Windows主机上传到Artifactory?

vxbzzdmp  于 5个月前  发布在  Windows
关注(0)|答案(1)|浏览(87)

我试图通过Ansible将文件从我的Windows主机上传到我的Artifactory存储库。
为了实现这一点,我试图使用一个CURL命令,从本地以下工程:

curl -u <username>:<password> -T C:\path\to\file.txt -k https://artifactory.blokes-server.net/artifactory/Data/

字符串
在Ansible中,我已经创建了以下剧本,它成功地通过我的模板运行,但实际上没有文件被放置在Artifactory repo中:

- name: Artifactory Interactions
  hosts: all

  tasks:
    - name: Upload files to Artifactory
      win_command:
        curl -u {{ ct_username }}:{{ ct_password }} -T {{ item.file_path }} -k {{ item.artifactory_path }} --ssl-no-revoke
      with_items: '{{ my_dictionary }}'


其中ct_usernamect_password是在Ansible Tower中创建的凭据,my_dictionary在Ansible Tower的extra-vars部分中传递,如下所示:

my_dictionary:
  - file_path: C:\path\to\file.txt
    artifactory_path: https://artifactory.blokes-server.net/artifactory/Data/


在这个实现中,我的playbook成功运行,但没有文件上传。但是,如果我在CURL命令中省略-k--ssl-no-revoke选项,我会收到以下错误:

schannel: next InitializeSecurityContext failed: Unknown error (0x80092013) - the revocation function was unable to check revocation because the revocation server was offline.


我的问题与this one类似,但不同之处在于我试图从Windows主机执行此操作,并且无法使用URI函数。

iyr7buue

iyr7buue1#

您需要在变量调用周围添加引号,以便Ansible将它们识别为变量,而不仅仅是字符串的一部分,而且由于您指定了-k, --insecure,因此不需要指定--ssl-no-revoke

- name: Artifactory Interactions
  hosts: all

  tasks:

    - name: Upload files to Artifactory
      win_command:
        curl -u "{{ ct_username }}":"{{ ct_password }}" -T "{{ item.file_path }}" -k "{{ item.artifactory_path }}" 
      with_items: '{{ my_dictionary }}'

字符串
老实说,这是我第一次使用Ansible时犯的一个简单的错误,看起来你走在正确的道路上,根据你的脚本/脚本的其余部分成为一名优秀的DevOps工程师!

相关问题