Salt stack:如何使用 Chocolate(状态)设置包安装检查

Salt stack: how to set up a package installation check with Chocolate (state)

在执行状态期间,管理器“Chocolate”安装了 RealVNC 包(程序 Files\Real VNC) 接下来,我在注册表中创建一个键。 我希望仅当 VNC 安装成功时才创建密钥。 我试过了

Require:
  - pkg: realvnc

Watch:
  - file: C:\Program Files\Real VNC\vncserver.exe

两个选项都告诉我找不到目标

SLS

      realvncsetup:
        chocolatey.installed:
          - name: realvnc

      reg1:
        reg.present:
          - name: HKEY_LOCAL_MACHINE\SOFTWARE\RealVNC\vncserver
          - vname: EnableAnalytics
          - vdata: "0"
          - vtype: REG_SZ
          - watch:
            - file: "C:\Program Files\RealVNC\VNC Server"

 

错误

ID: reg1
    Function: reg.present
        Name: HKEY_LOCAL_MACHINE\SOFTWARE\RealVNC\vncserver
      Result: False
     Comment: The following requisites were not found:
                                 require:
                                     file: C:\Program Files\RealVNC\VNC Server
     Started: 12:39:20.183205
    Duration: 0.0 ms
     Changes:   

盐 --versions

Salt Version:
           Salt: 3002.1
 
Dependency Versions:
           cffi: 1.12.2
       cherrypy: unknown
       dateutil: 2.7.3
      docker-py: 3.4.1
          gitdb: 2.0.5
      gitpython: 2.1.11
         Jinja2: 2.10
        libgit2: 0.27.7
       M2Crypto: Not Installed
           Mako: 1.0.7
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: 1.3.10
      pycparser: 2.19
       pycrypto: 2.6.1
   pycryptodome: 3.6.1
         pygit2: 0.27.4
         Python: 3.7.3 (default, Jul 25 2020, 13:03:44)
   python-gnupg: 0.4.4
         PyYAML: 3.13
          PyZMQ: 17.1.2
          smmap: 2.0.5
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.3.1
 
System Versions:
           dist: debian 10 buster
         locale: UTF-8
        machine: x86_64
        release: 4.19.0-6-amd64
         system: Linux
        version: Debian GNU/Linux 10 buster

我们提到的必要条件,例如requirewatch等,应该是对目标上运行“预定”的其他状态的引用。

关于watch

即使路径是通过安装“realvnc”包创建的,也没有处理路径的 Salt 状态。这就是它显示错误的原因。

引用 documentationwatch:

A watch requisite is used to add additional behavior when there are changes in other states.

所以如果你想看一个文件,那么应该有一个使用 file 模块“处理”文件的状态。

关于require

此外,在指定 require 时,您指的是 pkg 模块,因此 Saltstack 会为 realvnc 查找 pkg.installed。而您使用的是 chocolatey.installed.

因此,通过以下修改,它应该可以正常工作。

chocolatey-install-realvnc:
  chocolatey.installed:
  - name: realvnc

# Use the appropriate path that should exist when realvnc is installed
check-progfiles-path:
  file.exists:
  - name: 'C:\Program Files\Real VNC\vncserver.exe'

# You can use either or both for require as you see fit
create-registry-entry:
  reg.present:
  - name: HKEY_LOCAL_MACHINE\SOFTWARE\RealVNC\vncserver
  - vname: EnableAnalytics
  - vdata: "0"
  - vtype: REG_SZ
  - require:
    - file: 'C:\Program Files\Real VNC\vncserver.exe'
    - chocolatey: realvnc