mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 13:21:25 -07:00
ans-command and scripts.py for the basic cli parser to be imported elsewhere
This commit is contained in:
parent
ada866be46
commit
95706af074
2 changed files with 148 additions and 0 deletions
31
lib/ansible/scripts.py
Normal file
31
lib/ansible/scripts.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
from optparse import OptionParser
|
||||
import sys
|
||||
import constants as C
|
||||
|
||||
def base_ans_parser(opthosts=True, outputpath=True, forkdef=C.DEFAULT_FORKS):
|
||||
parser = OptionParser()
|
||||
if opthosts:
|
||||
parser.add_option('--host', default=[], action='append',
|
||||
help="hosts to act on, defaults to ALL")
|
||||
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('-u', '--user', default=C.DEFAULT_REMOTE_USER,
|
||||
dest='remote_user', help='set the default username')
|
||||
parser.add_option("-P", "--askpass", default=False, action="store_true",
|
||||
help="ask the user to input the ssh password for connecting")
|
||||
parser.add_option('-f','--forks', default=forkdef, type='int',
|
||||
help='set the number of forks to start up')
|
||||
if outputpath:
|
||||
parser.add_option('--outputpath', default='/tmp/ansible', dest="outputpath",
|
||||
help="basepath to store results/errors output.")
|
||||
return parser
|
||||
|
||||
# other functions as needed for nicely handling output from json back
|
||||
# to things people might be more inclined to deal with at a bash prompt
|
||||
|
||||
|
||||
def errorprint(msg):
|
||||
print >> sys.stderr, msg
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue