【发布时间】:2023-02-16 19:43:59
【问题描述】:
我正在尝试使用“salt.client”编写一个脚本,该脚本将在一组主机上运行指定的操作。文档位于 https://docs.saltproject.io/en/latest/ref/clients/index.html 给出了以下示例:
使用该示例,我编写的脚本是:
#!/usr/bin/env python3
import os
import salt.client
from multiprocessing import Pool
bootstrap_cmds = []
bootstrap_hosts = ['census-01630c42ebc397280*', 'consul-0090ff8a220eb6ff1*', 'consul-066f3dc733ebf89d8*', 'consul-037c95c90d235f723*']
for host in bootstrap_hosts:
hostCmd = salt.client.LocalClient().cmd(host, 'cmd.run', ['facter hostname ipaddress'])
bootstrap_cmds.append(hostCmd)
processes = (bootstrap_cmds)
def start_process(process_start):
os.system('python {}'.format(process_start))
start_pool = Pool(processes=len(bootstrap_cmds))
start_pool.map(start_process, processes)
当我运行脚本时,我得到以下响应:
python: can't open file '{consul-0090ff8a220eb6ff1.node.usge1prod.consul:': [Errno 2] No such file or directory
python: can't open file '{consul-037c95c90d235f723.node.usge1prod.consul:': [Errno 2] No such file or directory
python: can't open file '{consul-066f3dc733ebf89d8.node.usge1prod.consul:': [Errno 2] No such file or directory
python: can't open file '{census-01630c42ebc397280.node.usge1prod.consul:': [Errno 2] No such file or directory
附加到每个主机名的 '*' 是为了通配一些我们在 'consul' 中对主机名所做的时髦后缀——它在命令行中与 salt 一起工作。我怎样才能让它工作?
【问题讨论】:
标签: python multiprocessing salt-stack