0
点赞
收藏
分享

微信扫一扫

python系列之:本地执行bash命令,通过bash命令执行ansible命令


python系列之:本地执行bash命令,执行ansible命令

  • os.popen(command):command是要执行的bash命令
  • os.popen(command).read().strip():通过read输出执行命令的内容

import os
use = "f"
sparkAgent = "spakr-prod"
command = f"""
ansible-playbook 
--inventory=inventories/{sparkAgent} 
--user=f 
--private-key=/Users/{user}/{user}.private_key 
--ssh-common-args='-o ProxyCommand="/usr/local/bin/ncat --proxy optics-bj.nioint.com:8080 --proxy-type http %h %p"' update_spark_conf.yml
"""

# 执行update命令
commandOutput = os.popen(command).read().strip()

#根据ansible执行输出,判断状态        
successList = []
failedList = []
if commandOutput.find("failed=0") !=-1 and commandOutput.find("unreachable=0") !=-1:
	successList.append(flumeAgent)
else:
	failedList.append(flumeAgent)


举报

相关推荐

0 条评论