Web Services 使用file.managed下载Salt中的文件

rks48beu  于 2022-11-15  发布在  其他
关注(0)|答案(2)|浏览(175)

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

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

我不想将cmd.runCurlwget一起使用,因为这样会始终下载文件,即使文件已经在本地计算机上。
我想知道是否可能/存在以下选项之一:

*在线md5计算服务。有没有办法使用免费的网络服务来获取文件的md5哈希值?我想使用类似http://md5service.net?url={url-to-file}的服务。
*salt内部转换或解决方法。是否可以在Salt中处理此问题?也许可以通过某种方式忽略source_hash
*alternative state。Salt中是否还有其他状态可以执行类似操作,而不会失去仅在需要时下载文件的好处?

wztqucjr

wztqucjr1#

如果您无法控制其他服务器,请确保您可以信任该服务器下载其内容。不使用哈希将阻止您检测部分或损坏的下载。此外,也无法处理远程服务器上已更改的文件。
不过,你可以使用这样的状态来绕过散列码,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
isr3a4wc

isr3a4wc2#

从2016.3.0版开始,即使您没有访问哈希值的权限,也可以通过添加skip_verify: True来下载包含file.managed的文件。

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

来自文件:If True, hash verification of remote file sources (http://, https://, ftp://) will be skipped, and the source_hash argument will be ignored.

相关问题