此用例的目标是通过将 Linux 虚拟机连接到 Automation Config 环境,以编程方式在工作节点上安装 Salt 工作节点服务。

前提条件

在 Linux 环境中使用 API 部署工作节点之前,您必须:
  • 具有已部署 RaaS 的 Automation Config 环境。
  • 已安装 Salt 主节点和 Salt 工作节点。
  • 已部署 Linux 虚拟机。
  • 确保端口 22 未受防火墙保护且可供工作节点使用。

过程

  1. 确认文件夹 etc/salt/cloud.deploy.d 包含这些文件的集合。这些文件应与操作系统分发版本以及系统所需的 Salt 版本相匹配。
    Salt 主节点上 cloud.deploy.d 目录中所需文件的列表

    如果看不到这些文件,请联系支持部门。

    注: 文件名中的 xxxx(例如 salt-xxxx-redhat-8-x86_64-amd64.tar.gz)应与 Salt 主节点的版本相匹配。要验证 Salt 主节点的版本,请在 Salt 主节点上运行 salt-master -V 命令。
  2. 如果您的环境是气隙环境,请完成以下步骤:
    1. 打开 /etc/raas/raas 下的 RaaS 配置文件。
    2. 将以下行添加到该配置文件:
      minion_deployment:
        airgap_install: true
    3. 使用 service raas restart 命令重新启动 RaaS 服务。
    注: 如果使用的是强化 Linux 虚拟机,在某些情况下,无法从虚拟机上的 /tmp 运行脚本。
    • 如果使用的是 Automation Assembler 8.10.2 或更高版本:请将 additionalAuthParams 属性添加到云模板中的 Automation Config 资源。有关详细信息,请参见将 Automation Config 资源添加到云模板
      additionalAuthParams:
        profile:
          tmp_dir: /var/cache/salt
    • 如果使用的是 Automation Assembler 8.10.1 或更低版本:请使用以下内容修改 /etc/salt/cloud.providers.d/ssc_saltify_provider.conf 文件
      ssc_saltify_provider:
        driver: saltify
        tmp_dir: /var/cache/salt
      如果此配置文件不存在,请创建该文件并添加上述设置。
  3. 要确定 Salt 主节点的 FQDN,请在 Salt 主节点的终端运行 salt saltmaster grains.get fqdn 命令。
  4. 运行 ping [FQDN] 命令,确保已为 Salt 主节点配置 FQDN。
    在 Linux 计算机上运行 ping FQDN 命令的结果
  5. 要打开 Python,请运行 python3
  6. 使用 SSEAPI 客户端执行以下 API 调用并使用适用于您环境的正确凭据:
    from sseapiclient import APIClient
    
    client = APIClient('https://<master-ip>', '<ssc-username>', '<sscpassword>', ssl_validate_cert=False)
    
    
    client.api.minions.deploy_minion(
    
     master_id = '<master-id>',
    
     host_name_ip = '<prospective minion’s ip>',
    
     os = ‘<prospective minion’s os>’,
    
     minion_id = '<desired-minion-name-for-prospective-minion>',
    
     username = '<ssh-username-for-prospective-minion>', 
    
     password = '<ssh-password-for-prospective-minion>',
    
    )

    deploy.minion 函数开始在 Automation Config 环境中运行。您可以在 Automation Config 用户界面的活动选项卡中验证作业是否正在运行。

    注: 如果要从 Automation Assembler 部署工作节点,Automation Assembler 将执行此 API 调用。

结果

工作节点已在 Linux 环境中通过 API 调用成功部署并配置。

下一步做什么

通过以下两种方法验证是否已成功部署工作节点:使用 运行命令窗口对工作节点运行 test.ping 命令;或在 Salt 主节点命令窗口中运行 \* test.ping\* test.versions 命令。