python系列之:代码执行ansible-playbook命令
一、ansible-playbook命令
- ansible-playbook --inventory=inventories/passwd-service --user=f --private-key=/data/f/f.private_key updata_passwd_json.yml
二、python调用ansible-playbook命令代码
def syncPassword():
os.chdir("/data/f/passwdPushService/passwdService/")
command = f"""
ansible-playbook --inventory=inventories/passwd-service --user=f --private-key=/data/f/f.private_key updata_passwd_json.yml
"""
print(command)
commandOutput = os.popen(command).read().strip()
if commandOutput.find("failed=0") != -1 and commandOutput.find("unreachable=0") != -1:
info = f"配置更新成功"
else:
info = f"配置更新失败"
print(info)