蓝晶灵 发表于 2018-1-2 21:48:39

ansible 自动化(3)

#!/usr/bin/python  import ansible.runner
  import sys
  # construct the ansible runner and execute on all hosts
  results = ansible.runner.Runner(
  pattern='*', forks=10,
  module_name='command', module_args='/usr/bin/uptime',
  ).run()
  if results is None:
  print "No hosts found"
  sys.exit(1)
  print "UP ***********"
  for (hostname, result) in results['contacted'].items():
  if not 'failed' in result:
  print "%s >>> %s" % (hostname, result['stdout'])
  print "FAILED *******"
  for (hostname, result) in results['contacted'].items():
  if 'failed' in result:
  print "%s >>> %s" % (hostname, result['msg'])
  print "DOWN *********"
  for (hostname, result) in results['dark'].items():
  print "%s >>> %s" % (hostname, result)
页: [1]
查看完整版本: ansible 自动化(3)