mirror of
				https://github.com/ansible-collections/community.general.git
				synced 2025-10-26 13:56:09 -07:00 
			
		
		
		
	
		
			
				
	
	
		
			31 lines
		
	
	
	
		
			860 B
		
	
	
	
		
			Python
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
	
		
			860 B
		
	
	
	
		
			Python
		
	
	
		
			Executable file
		
	
	
	
	
| #!/usr/bin/python
 | |
| # (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
 | |
| # example of getting the uptime of all hosts, 10 at a time
 | |
| 
 | |
| 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)
 | |
| 
 |