Search code examples
authenticationsalt-project

Is it possible to download a file that requires authentication using SaltStack's file.managed state?


I've been reading through the file.managed documentation and there are plenty of examples of downloading files from URLs. However, none of these examples mention using any forms of authentication such as a username and password. I already know about cmd.run, I am specifically asking about the file.managed module.

Is it possible to download files that require authentication using this module?

Here is an example cURL command that I want to implement using the file.managed state module instead:

curl -L -u "username:password" -O https://mywebsite.com/important_file.tar.gz

Solution

  • Yes. The standard URI authentication is supported:

    download file:
      file.managed:
        - name: /target
        - source: https://username:password@mywebsite.com/important_file.tar.gz
    

    You'll probably want to template the password in from pillar/sdb to reduce its exposure.

    This will work for any state that uses source URLs, including archive.extracted.