安装并集成 Automation Config 服务后,还需要在计划使用 Automation Config 进行管理的任何节点上安装、运行和注册 Salt 工作节点服务。可以通过以下两种方法将 Salt 工作节点服务部署到节点:使用 VMware Aria Automation 云模板或通过安全 Shell (SSH) 安装服务。

Salt 及其与 Automation Config 的关系

Automation Config 在 Salt 上运行,Salt 是一个基于 Python 的开源远程执行框架,用于:

  • 配置管理
  • 自动化
  • 置备
  • 编排

Salt 是 Automation Config 核心功能的底层技术。Automation Config 增强并扩展了 Salt,提供了其他功能和特性,改进了易用性。

Salt 使用控制器-客户端模型,在此模型中,控制器向客户端发出命令,而客户端执行命令。在 Salt 生态系统中,控制器是运行 Salt 主节点服务的服务器。它向一个或多个 Salt 工作节点发出命令,这些工作节点是运行 Salt 工作节点服务并在该特定主节点中注册的节点。

还可以将 Salt 描述为发布者-订阅者模型。主节点发布需要执行的作业,而工作节点订阅这些作业。当特定作业应用于工作节点时,该工作节点将执行该作业。在工作节点完成作业执行后,会将作业返回数据发送回主节点。

工作节点是运行 salt-minion 服务的节点。该服务侦听 Salt 主节点发出的命令并执行请求的任务。可以从 VMware Aria Automation 云模板部署工作节点。

必须先在要管理的所有节点上安装 Salt 工作节点服务,然后才能开始使用 Automation Config 进行配置管理。此外,还必须通过向 Automation Config 发送并接受密钥来注册工作节点。

开始前

  • 安装和配置 Automation Config 并将其与 VMware Aria Automation 集成。
  • Automation Config 管理的节点必须能够访问 Salt 主节点,并且必须与 Automation Config 集成点和 Salt 主节点位于同一网络。
  • 部署到专用网络的 vSphere 计算机必须能够启动与 Automation Config 集成和 Salt 主节点的连接。

通过 SSH 安装 Salt 工作节点服务

使用 SSH 安装 Salt 工作节点服务的过程取决于在这些节点上运行的操作系统。

安装 Salt 工作节点服务后,请执行以下操作:
  1. /etc/salt/minion.d 目录中创建 master.conf 文件,配置每个工作节点以与主节点通信。在此文件中,提供主节点的 IP 地址。例如:master: 192.0.2.1
  2. 启动工作节点服务:

    sudo systemctl enable salt-minion

    sudo systemctl start salt-minion

  3. 对其余的所有节点重复上述步骤。

配置这些工作节点文件以指向 Salt 主节点后,在 Automation Config 服务的“工作节点密钥”工作区中接受工作节点密钥。

使用 VMware Aria Automation 云模板安装 Salt 工作节点服务

要使用云模板部署 Salt 工作节点服务,您必须能够访问并熟练使用 cloud-init (Linux) 或 Cloudbase-init (Windows)。要将 Salt 工作节点添加到为 Automation Config 集成配置的 Salt 主节点,云模板中的虚拟机必须支持 cloud-init (Linux) 或 Cloudbase-init (Windows)。

以下部分介绍了如何使用云模板部署 Salt 工作节点服务。

将工作节点添加到为 VMware Aria Automation 配置的 Salt 主节点

安装 Automation Config 时,将指定 Salt 主节点 IP 地址。从 VMware Aria Automation 云模板部署工作节点时,将使用该主节点 IP 地址作为 masterAddress 属性。

需要在 VMware Aria Automation 云模板或部署中通过使用 cloud-init 或 Cloudbase-init 脚本安装和部署工作节点。此外,还可以使用表示使用这些格式之一的云配置脚本的映像映射。要将 Salt 工作节点添加到与 VMware Aria Automation Automation Config 集成关联的 Salt 主节点,目标虚拟机必须支持 cloud-init (Linux) 或 Cloudbase-init (Windows)。VMware Aria Automation 云配置脚本支持这两种格式。

可以在云模板中配置具有 minionId 值和 cloudConfig 值的计算机资源,并引用属性组 SaltStackConfiguration。在 VMware Aria Suite Lifecycle 中安装和配置 Automation Config 服务时会创建 SaltStackConfiguration 属性组。它包含 masterAddressmasterFingerprint 属性。

minionId 值必须与为云模板代码 cloudConfig 部分中的计算机 /salt/minion_id 指定的值相匹配。

下面显示了基于 Windows 和基于 Linux 的 VMware Aria Automation 云模板代码示例。请注意,可以使用以下任一方法指定云配置脚本:
  • 从云模板代码调用的 VMware Aria Automation 映像
  • 从云模板代码调用的云配置脚本
  • 直接添加到云模板代码的云配置脚本内容

注意:部署包含 Salt 工作节点的云模板时,如果部署在 Automation Assembler 中不可见,则可以使用 Automation Service Broker 服务显示部署。

示例 - 基于 Linux 的部署和 cloud-init

为支持 cloud-init 的基于 Linux 的计算机部署工作节点的云模板配置示例如下所示:
resources:
  Salt-Minion:
    type: Cloud.Machine
    properties:
      image: Ubuntu-18
      flavor: medium
      constraints:
        - tag: 'env:vsphere'
      cloudConfig: |
        #cloud-config
        hostname: ${input.saltminionhostname}
        users:
          - name: ${input.user}
            sudo: ['ALL=(ALL) NOPASSWD:ALL']
            groups: sudo
            shell: /bin/bash
        runcmd:
          - PASS=${input.password}
          - USER=${input.user}
          - echo $USER:$PASS | /usr/sbin/chpasswd
          - sed -i "s/PasswordAuthentication no/PasswordAuthentication yes/g" /etc/ssh/sshd_config
          - service ssh reload
          - curl -L https://bootstrap.saltstack.com -o install_salt.sh
          - sudo sh install_salt.sh -A ${propgroup.SaltStackConfiguration.masterAddress}

示例 - 基于 Windows 的部署和 Cloudbase-init

为支持 Cloudbase-init 的基于 Windows 的计算机部署工作节点的云模板配置示例如下所示:
formatVersion: 1
inputs: {}
resources:
  WindowsVM-Minion:
    type: Cloud.vSphere.Machine
    properties:
      image: win2016
      flavor: medium
      customizationSpec: Windows
      minionId: '${resource.WindowsVM-Minion.resourceName}'
      networks:
        - network: '${resource.wpnet.id}'
          name: '${wpnet.name}'
          assignPublicIpAddress: true
      cloudConfig: |
        #ps1_sysnative
        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -OutFile C:\Salt-Minion-3002.2-Py3-AMD64-Setup.exe -Uri https://repo.saltstack.com/windows/Salt-Minion-3002.2-Py3-AMD64-Setup.exe
        Start-Process -Wait -FilePath "C:\Salt-Minion-3002.2-Py3-AMD64-Setup.exe" -ArgumentList "/S" -PassThru
        ((Get-Content -path C:\salt\conf\minion -Raw) -replace "#master: salt", "master: ${propgroup.SaltStackConfiguration.masterAddress}") | Set-Content -Path C:\salt\conf\minion
        ((Get-Content -path C:\salt\conf\minion -Raw) -replace "#master_finger: ''", "master_finger: '${propgroup.SaltStackConfiguration.masterFingerPrint}'") | Set-Content -Path C:\salt\conf\minion
        Set-Content -Path C:\salt\conf\minion_id -Value '${resource.WindowsVM-Minion.resourceName}'
        C:\salt\salt-call.bat service.restart salt-minion
  wpnet:
    type: Cloud.Network
    properties:
      name: wpnet
      networkType: existing

如何配置 PowerShell 命令

您可以在云模板的 cloudConfig 部分中配置 PowerShell 命令。

启用 PowerShell 命令之前,请从 Salt 存储库网站下载 Salt 工作节点软件包。然后完成下列步骤:
  1. 在 Windows 虚拟机中安装 Salt 工作节点服务。
  2. 更新工作节点配置中的 Salt 主节点主机名值。
  3. 更新工作节点配置中的 Salt 主节点指纹值。
  4. minion_id 设置为将用于接受 Salt 主节点上工作节点的虚拟机资源名称。
  5. 重新启动最小值。

有关部署 Salt 工作节点的更多信息

有关使用集成 Automation ConfigVMware Aria Automation 云模板部署 Salt 工作节点的替代方法,请参见 Assembly 和 ABX 密钥(以及如何使用它们安装 Automation Config 工作节点代理)

有关在通常情况下定义和部署 Automation Assembler 模板的相关信息,尤其是熟悉 Config 但不熟悉 Aria Automation 的情况下,请参见设计 Assembler 部署