ansible-playbook - python中执行带参数的playbook

先简单记录下
playbook 带参数用-e

import commands

playbook_web = '~/xxx/cognos_cluster_stop.yml'
hosts = '~/xxx/hosts_cluster_stop'
params_web = "{'hosts': 'web', 'opr_type': 'stop'}"
log_file = '~/xxx/ansible.log'

cmd_prefix = "set -o pipfail;/home/wfq/python/bin/ansible-playbook {0} -i {1} -e '{2}' | tee -a {3}"

exec_cmd = cmd_prefix.format(playbook_web, hosts, params_web, log_file)
# 执行
(status, output) = commands.getstatusoutput('bash -c "{0}"'.format(exec_cmd))

status = 0 不一定执行就成功了;

你可能感兴趣的:(Ansible)