在同一主机上并行运行ansible playbooks

时间:2017-11-08 21:49:14

标签: python linux multithreading parallel-processing ansible

我正在尝试运行30个os.commands,它们在python脚本中以线程并行方式在同一主机上运行ansible-playbook。如果我以连续方式运行30个ansible-playbooks,它将完成所有30个工作。但是当我尝试以并行的方式运行它们时,一些剧本可以完成一些不执行任务的任务。 Python正在处理剧本的线程运行。我认为当ansible试图在同一主机上同时运行多个ansible-playbook时会发生冲突。如何在同一台主机上同时运行30个线程播放器。

def runOsCommand( systemCommand ):
    print(systemCommand)
    logging.info(" "+systemCommand)
    os.system(systemCommand)

def createProfile( Profile,ProfileDesc ):
    Command= "ansible-playbook create-profile.yml  --extra-vars \"VARIABLE1=" + str(Profile) + " " +  "VARIABLE2=" + str(ProfileDesc) +"\""
    runOsCommand(Command)
    return

class Thread (threading.Thread):
    def __init__(self, threadID, name, counter):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name
        self.counter = counter
    def run(self):
        print "Starting " + self.name
        createProfile(Profile,ProfileDesc)     
        print "Exiting " + self.name

for iter in range(30):
    mythreadx = Thread(iter, "Thread-Datapool-Row-"+str(iter), iter)
    mythreadx.start()

0 个答案:

没有答案