使用 file.managed 在 Salt 中下载文件

Using file.managed for downloading a file in Salt

salt.states.file.managedsource_hash 作为参数来验证下载的文件。这阻止我对我无法控制的在线服务器上的文件使用 file.managed。该文件也会定期更改。我的配置如下所示。

download_stuff:
  file.managed:
    - name: localfile.tar.gz
    - source: http://someserver.net/onlinefile.tar.gz
    - source_hash: ???

我不想将 cmd.runCurlwget 一起使用,因为这将始终下载文件,即使它已经在本地计算机上也是如此。

我想知道下面的选项之一是否是 possible/exists:

如果您无法控制其他服务器,请确保您可以信任它来下载其内容。不使用哈希将阻止您检测部分或损坏的下载。也无法处理远程服务器上已更改的文件。

不过,您可以使用这样的状态来绕过哈希码。 creates 部分将在文件下载后阻止第二次下载:

bootstrap:
  cmd.run:
    - name: curl -L https://bootstrap.saltstack.com -o /etc/salt/cloud.deploy.d/bootstrap-salt.sh
    - creates: /etc/salt/cloud.deploy.d/bootstrap-salt.sh