如何预先播种 Salt Minion 的档案

如何预先播种 Salt Minion 的档案

因此,我正在创建一个状态文件以在 minion 上安装 MatterMost。到目前为止,它看起来像这样:


mattermost-usergroup:
  user.present:
    - name: mattermost
    - shell: /bin/sh
    - createhome: False
    - usergroup: True
    - system: True
    - require:
      # From postgresql-formula:
      # https://github.com/saltstack-formulas/postgres-formula/blob/master/postgres/server/init.sls#L278
      - service: postgresql-running

mattermost-opt:
  archive.extracted:
    - name: /opt
    - source: https://releases.mattermost.com/{{ pillar['mattermost'].version }}/mattermost-{{ pillar['mattermost'].version }}-linux-amd64.tar.gz
    - source_hash: a194fd3d2bebed8e6b5721261621030e573f4500c54fb251cfd8ff6f32fe714e
    - user: mattermost
    - group: mattermost
    - require:
      - user: mattermost-usergroup

我的问题是:在创建此 SLS 之前,已经通过将 tarball 下载到管理员主目录,然后手动将 tarball 提取到 来安装了 MatterMost(与支柱中指定的版本完全相同)opt。如果我运行state.highstate此操作,我担心它会重新下载 tarball,然后因为 tarball 是“新的”(从 Minion 的角度来看),它将被提取到现有安装中/opt

我如何“预先播种” Minion 的“存档缓存”,以便 Minion 可以看到文件已下载,并且不会(重新)下载+覆盖?

答案1

我刚刚测试过(sls 做了一些修改,没有支柱,因此将测试版本硬编码在一次性 nspawn 容器中)。我首先使用 /opt 目标下载了 tarball,然后将下载的目录复制到 /mnt。

mattermost-opt:
  archive.extracted:
    - name: /mnt
    - source: https://releases.mattermost.com/desktop/5.0.4/mattermost-desktop-5.0.4-linux-x64.tar.gz
    - source_hash: sha256=cbd2981ce282eecfea1167c500d900cdd31bd041b0861025743b7d58e4cb9229
    - user: mattermost
    - group: mattermost
    - require:
      - mattermost-usergroup

它运行正常。无需额外下载。事实上,如果存档缓存在 /var/cache/salt/minion/extrn_files/{{saltenv}} 中,存档状态足够小,无需重新下载存档,如果文件丢失,它将验证哈希值并在目标目录中解压内容。

因此这里什么也不做,一切都已准备就绪:

    # salt-call state.apply mattermost 
    local:
    ----------
              ID: mattermost-usergroup
        Function: user.present
            Name: mattermost
          Result: True
         Comment: User mattermost is present and up to date
         Started: 21:09:26.078971
        Duration: 12.33 ms
         Changes:   
    ----------
              ID: mattermost-opt
        Function: archive.extracted
            Name: /mnt
          Result: True
         Comment: All files in archive are already present
         Started: 21:09:26.091829
        Duration: 1030.216 ms
         Changes:   
    
    Summary for local
    ------------
    Succeeded: 2
    Failed:    0
    ------------
    Total states run:     2
    Total run time:   1.043 s

我们从解压的档案中删除一个文件并重试:

# rm /mnt/mattermost-desktop-5.0.4-linux-x64/vk_swiftshader_icd.json                 # salt-call state.apply mattermost 

  local:
----------
          ID: mattermost-usergroup
    Function: user.present
        Name: mattermost
      Result: True
     Comment: User mattermost is present and up to date
     Started: 21:09:45.753688
    Duration: 11.511 ms
     Changes:   
----------
          ID: mattermost-opt
    Function: archive.extracted
        Name: /mnt
      Result: True
     Comment: https://releases.mattermost.com/desktop/5.0.4/mattermost-desktop-5.0.4-linux-x64.tar.gz extracted to /mnt/, due to absence of one or more files/dirs. Output was trimmed to False number of lines
     Started: 21:09:45.765712
    Duration: 2165.587 ms
     Changes:   
              ----------
              extracted_files:
              {{ trimmed output }}
                  - mattermost-desktop-5.0.4-linux-x64/vk_swiftshader_icd.json
              updated ownership:
                  True

Summary for local
------------
Succeeded: 2 (changed=1)
Failed:    0
------------
Total states run:     2
Total run time:   2.177 s

相关内容