Search code examples
curlansibleartifactoryansible-2.xansible-template

How can I upload to Artifactory using Ansible from a Windows host?


I am trying to upload files from my Windows host to my Artifactory repo through Ansible.

To achieve this I am trying to use a CURL command, from local the following works:

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

In Ansible I have created the following playbook that runs successfully through my template, however no file is actually placed in the 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 }}'

where ct_username and ct_password are credentials created in Ansible Tower, and my_dictionary is passed in the extra-vars section of Ansible Towers as so:

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

With this implementation my playbook runs successfully but no file is uploaded. However if I omit the -k and --ssl-no-revoke options in my CURL command I do receive the following error:

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

My question is similar to this one but differs because I am attempting to do this from a Windows host and cannot use the URI function.


Solution

  • You need to add quotes around your variable calls so that Ansible recognizes them as a variable and not just a part of the string, also since you specify -k, --insecure you shouldn't need to specify --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 }}'
    

    Honestly it's a simple mistake I made when I first started with Ansible as well, seems like you're on the right path to becoming a good DevOps engineer based on the rest of your scripts/configs!