|
#!/usr/bin/python
import ansible.runner
import sys
# construct the ansible runner and execute on all hosts
results = ansible.runner.Runner(
host_list='/root/hosts',
pattern='*', forks=10,
module_name='command', module_args='which systemctl',
).run()
if results is None:
print "No hosts found"
sys.exit(1)
print "\033[32mUP ***********\033[0m"
for (hostname, result) in results['contacted'].items():
if not 'failed' in result:
if len(result['stdout']):
print "%s >>>stdout: %s" % (hostname, result['stdout'])
if len(result['stderr']):
print "%s >>>stderr: %s" % (hostname, result['stderr'])
print "\033[31mFAILED *******\033[0m"
for (hostname, result) in results['contacted'].items():
if 'failed' in result:
print "%s >>> %s" % (hostname, result['msg'])
print "\033[33mDOWN *********\033[0m"
for (hostname, result) in results['dark'].items():
print "%s >>> %s" % (hostname, result) |
|
|