#!/usr/bin/env python
# -*- coding: utf-8 -*-


import spam.ansirunner
import spam.plugins.rados as rados

host_list = ["11.111.11.1", "11.113.11.1", "11.111.11.13"]
remote_user = "wwot"
remote_pass = "wwwwwwwwww3"

def execute_ping():
    '''
    Execute ls on some hosts
    '''
    runner = spam.ansirunner.AnsibleRunner()
    result, failed_hosts = runner.ansible_perform_operation(
        host_list=host_list,
        remote_user=remote_user,
        remote_pass=remote_pass,
        module="ping")

    print result, failed_hosts
    dark_hosts = runner.ansible_get_dark_hosts(result)
    print "dark hosts: ", dark_hosts


def execute_ls():
    '''
    Execute any adhoc command on the hosts.
    '''
    runner = spam.ansirunner.AnsibleRunner()
    result, failed_hosts = runner.ansible_perform_operation(
        host_list=host_list,
        remote_user=remote_user,
        remote_pass=remote_pass,
        module="command",
        module_args="ls -1")

    print "Result: ", result


def execute_rados_df():
    runner = spam.ansirunner.AnsibleRunner()
    result, failed_hosts = runner.ansible_perform_operation(
        host_list=host_list,
        remote_user=remote_user,
        remote_pass=remote_pass,
        module="command",
        module_args="rados df")

    print "Result: ", result


def execute_rados_df2():
    rados_handle = rados.Rados()
    result = rados_handle.rados_df(host_list=["10.163.41.4"],
                                   remote_user=remote_user,
                                   remote_pass=remote_pass)

    #result, failed_hosts = rados_handle.perform_operation(
    #    host_list=["10.163.41.4"],
    #    remote_user=remote_user,
    #    remote_pass=remote_pass,
    #    cmd="rados df")
    print "RESULTS: ", result['contacted']['10.163.41.4']['parsed_results']



def main():
    '''
    Simple examples
    '''
    execute_ping()
    #execute_ls()
    #execute_rados_df()
    execute_rados_df2()


if __name__ == '__main__':
    main()

@@ -40,16 +40,56 @@
 -8 -*-%0A%0A
+import os%0Aimport argparse%0Aimport getpass
 %0Aimport 
@@ -144,67 +144,37 @@
 os%0A%0A
-host_list = %5B%2211.111.11.1%22, %2211.113.11.1%22, %2211.111.11.13%22%5D%0A
+%0Adef execute_ping(host_list, 
 remo
@@ -184,18 +184,10 @@
 user
+,
  
-= %22wwot%22%0A
 remo
@@ -197,43 +197,8 @@
 pass
- = %22wwwwwwwwww3%22%0A%0Adef execute_ping(
 ):%0A 
@@ -606,16 +606,51 @@
 cute_ls(
+host_list, remote_user, remote_pass
 ):%0A    '
@@ -1013,16 +1013,51 @@
 ados_df(
+host_list, remote_user, remote_pass
 ):%0A    r
@@ -1364,16 +1364,51 @@
 dos_df2(
+host_list, remote_user, remote_pass
 ):%0A    r
@@ -1476,39 +1476,33 @@
 f(host_list=
-%5B%2210.163.41.4%22%5D
+host_list
 ,%0A          
@@ -1620,337 +1620,1064 @@
     
-#result, failed_hosts = rados_handle.perform_operation(%0A    #    host_list=%5B%2210.163.41.4%22%5D,%0A    #    remote_user=remote_user,%0A    #    remote_pass=remote_
+print %22RESULTS: %22, result%5B'contacted'%5D%0A%0A%0Adef parse_arguments():%0A    parser = argparse.ArgumentParser(prog=%22cloudops.py%22,%0A                                     description=%22CPE Cloud Ops %22)%0A%0A    parser.add_argument(%22--hosts%22,%0A                        help=%22Hosts to execute operations on%22,%0A                        nargs='+',%0A                        required=True)%0A    parser.add_argument(%22--username%22,%0A                        help=%22Username for remote hosts%22,%0A                        required=True)%0A    parser.add_argument(%22--ask-
 pass
+%22
 ,%0A    
-#
     
-cmd=%22rados df%22)%0A    print %22RESULTS: %22, result%5B'contacted'%5D%5B'10.163.41.4'%5D%5B'parsed_results'%5D%0A%0A%0A%0Adef main():%0A    '''%0A    Simple examples%0A    '''%0A    execute_ping(
+                help=%22Ansible operation will prompt for user password%22,%0A                        action=%22store_true%22)%0A%0A    args = parser.parse_args()%0A    return args%0A%0A%0Adef main():%0A    '''%0A    Simple examples%0A    '''%0A    args = parse_arguments()%0A    if args.askpass:%0A        password = getpass.getpass(%22Password: %22)%0A%0A    if not args.username:%0A        username = getpass.getuser()%0A%0A    host_list = args.remote_hosts%0A    os.environ%5B%22ANSIBLE_HOST_KEY_CHECKING%22%5D = %22False%22%0A%0A    execute_ping(host_list, username, password
 )%0A  
@@ -2738,16 +2738,45 @@
 dos_df2(
+host_list, username, password
 )%0A%0A%0Aif _

Modify example to use cmd line args.