运行自动化网格作业

自动化网格是可扩展的 Receptor 节点集群,用于执行 Ansible playbook。Ansible SDK 允许您直接在自动化网格中的节点上调用作业。

开始之前

  • 安装 Ansible SDK 和所需软件。

  • 安装 Ansible Receptor

使用 examples/receptor_config 目录中的配置文件,创建本地运行的 Receptor 节点集群。

  1. 打开您的 /etc/hosts 文件进行编辑。

  2. 将以下条目添加到您的 hosts 文件中

    127.0.0.1 foo.example.com
    127.0.0.1 bar.example.com
    127.0.0.1 baz.example.com
    
  3. 打开一个终端并启动第一个 Receptor 节点。

    1. 激活您的 Ansible SDK 虚拟环境。

      $ source env/bin/activate
      
    2. 使用 foo.yml 配置启动节点。

      $ receptor --config foo.yml
      
  4. 打开一个新的终端并启动第二个 Receptor 节点。

    1. 激活您的 Ansible SDK 虚拟环境。

    2. 使用 bar.yml 配置启动节点。

      $ receptor --config bar.yml
      
  5. 打开一个新的终端并启动第三个 Receptor 节点。

    1. 激活您的 Ansible SDK 虚拟环境。

    2. 使用 baz.yml 配置启动节点。

      $ receptor --config baz.yml
      
  6. 验证自动化网格是否正在运行。

    $ receptorctl --socket /tmp/bar.sock status
    

使用 Ansible SDK 在网格上运行示例自动化作业,如下所示

  1. 打开一个终端并切换到 examples 目录。

  2. 运行以下命令

    $ python example_mesh_job.py
    

example_mesh_job.py 程序有一个 main() 函数,该函数连接到 Receptor 节点并运行 examples/datadir/project/pb.yml playbook。当 Ansible SDK 将以下内容打印到 stdout 时,您可以验证作业是否成功

submitting work
work submitted
payload builder completed ok
getting results
got results
waiting for jobs
job done: True, has <x> events

故障排除

如果您遇到此方案的问题,请按以下方式进行故障排除

  • 确保已安装 receptorctl

  • 确保您的 /etc/hosts 文件包含每个本地 Receptor 节点的条目。

  • 确保在 Ansible SDK 虚拟环境中使用单独的终端运行每个 Receptor 节点。

您可以在 故障排除 中找到更多帮助