|
|
@ -25,6 +25,7 @@ import shlex
|
|
|
|
import ansible.runner
|
|
|
|
import ansible.runner
|
|
|
|
import ansible.playbook
|
|
|
|
import ansible.playbook
|
|
|
|
import ansible.constants as C
|
|
|
|
import ansible.constants as C
|
|
|
|
|
|
|
|
from ansible.scripts import base_ans_parser
|
|
|
|
|
|
|
|
|
|
|
|
class Cli(object):
|
|
|
|
class Cli(object):
|
|
|
|
|
|
|
|
|
|
|
@ -32,26 +33,11 @@ class Cli(object):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def runner(self):
|
|
|
|
def runner(self):
|
|
|
|
parser = OptionParser()
|
|
|
|
parser = base_ans_parser()
|
|
|
|
parser.add_option("-P", "--askpass", default=False, action="store_true",
|
|
|
|
|
|
|
|
help="ask the user to input the ssh password for connecting")
|
|
|
|
|
|
|
|
parser.add_option("-H", "--host-list", dest="host_list",
|
|
|
|
|
|
|
|
help="path to hosts list", default=C.DEFAULT_HOST_LIST)
|
|
|
|
|
|
|
|
parser.add_option("-L", "--library", dest="module_path",
|
|
|
|
|
|
|
|
help="path to module library", default=C.DEFAULT_MODULE_PATH)
|
|
|
|
|
|
|
|
parser.add_option("-f", "--forks", dest="forks", type="int",
|
|
|
|
|
|
|
|
help="level of parallelism", default=C.DEFAULT_FORKS)
|
|
|
|
|
|
|
|
parser.add_option("-n", "--name", dest="module_name",
|
|
|
|
parser.add_option("-n", "--name", dest="module_name",
|
|
|
|
help="module name to execute", default=C.DEFAULT_MODULE_NAME)
|
|
|
|
help="module name to execute", default=C.DEFAULT_MODULE_NAME)
|
|
|
|
parser.add_option("-a", "--args", dest="module_args",
|
|
|
|
parser.add_option("-a", "--args", dest="module_args",
|
|
|
|
help="module arguments", default=C.DEFAULT_MODULE_ARGS)
|
|
|
|
help="module arguments", default=C.DEFAULT_MODULE_ARGS)
|
|
|
|
parser.add_option("-p", "--pattern", dest="pattern",
|
|
|
|
|
|
|
|
help="hostname pattern", default=C.DEFAULT_PATTERN)
|
|
|
|
|
|
|
|
parser.add_option("-u", "--remote-user", dest="remote_user",
|
|
|
|
|
|
|
|
help="remote username", default=C.DEFAULT_REMOTE_USER)
|
|
|
|
|
|
|
|
parser.add_option("-r", "--run-playbook", dest="playbook",
|
|
|
|
|
|
|
|
help="playbook file, instead of -n and -a", default=None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: more shell like splitting on module_args would
|
|
|
|
# TODO: more shell like splitting on module_args would
|
|
|
@ -61,7 +47,6 @@ class Cli(object):
|
|
|
|
if options.askpass:
|
|
|
|
if options.askpass:
|
|
|
|
sshpass = getpass.getpass(prompt="SSH password: ")
|
|
|
|
sshpass = getpass.getpass(prompt="SSH password: ")
|
|
|
|
|
|
|
|
|
|
|
|
if options.playbook is None:
|
|
|
|
|
|
|
|
return ansible.runner.Runner(
|
|
|
|
return ansible.runner.Runner(
|
|
|
|
module_name=options.module_name,
|
|
|
|
module_name=options.module_name,
|
|
|
|
module_path=options.module_path,
|
|
|
|
module_path=options.module_path,
|
|
|
@ -73,16 +58,6 @@ class Cli(object):
|
|
|
|
pattern=options.pattern,
|
|
|
|
pattern=options.pattern,
|
|
|
|
verbose=True,
|
|
|
|
verbose=True,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
|
|
|
|
return ansible.playbook.PlayBook(
|
|
|
|
|
|
|
|
playbook=options.playbook,
|
|
|
|
|
|
|
|
module_path=options.module_path,
|
|
|
|
|
|
|
|
remote_user=options.remote_user,
|
|
|
|
|
|
|
|
remote_pass=sshpass,
|
|
|
|
|
|
|
|
host_list=options.host_list,
|
|
|
|
|
|
|
|
forks=options.forks,
|
|
|
|
|
|
|
|
verbose=True
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
|
|