Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
7b9856bc
Commit
7b9856bc
authored
Apr 06, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modification on top of skvidal's common options patch to keep options to command line tools sorted.
parent
8e1f24b8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
58 deletions
+91
-58
bin/ansible
+17
-6
bin/ansible-playbook
+13
-19
lib/ansible/utils.py
+61
-33
No files found.
bin/ansible
View file @
7b9856bc
...
@@ -47,12 +47,23 @@ class Cli(object):
...
@@ -47,12 +47,23 @@ class Cli(object):
def
parse
(
self
):
def
parse
(
self
):
''' create an options parser for bin/ansible '''
''' create an options parser for bin/ansible '''
parser
=
utils
.
base_parser
(
constants
=
C
,
runas_opts
=
True
,
async_opts
=
True
,
output_opts
=
True
,
usage
=
'ansible <host-pattern> [options]'
)
options
=
{
parser
.
add_option
(
'-a'
,
'--args'
,
dest
=
'module_args'
,
'-a'
:
dict
(
long
=
'--args'
,
dest
=
'module_args'
,
help
=
"module arguments"
,
default
=
C
.
DEFAULT_MODULE_ARGS
)
help
=
"module arguments"
,
default
=
C
.
DEFAULT_MODULE_ARGS
),
parser
.
add_option
(
'-m'
,
'--module-name'
,
dest
=
'module_name'
,
'-m'
:
dict
(
long
=
'--module-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
=
utils
.
make_parser
(
options
,
usage
=
'ansible <host-pattern> [options]'
,
runas_opts
=
True
,
async_opts
=
True
,
output_opts
=
True
,
)
options
,
args
=
parser
.
parse_args
()
options
,
args
=
parser
.
parse_args
()
self
.
callbacks
.
options
=
options
self
.
callbacks
.
options
=
options
...
...
bin/ansible-playbook
View file @
7b9856bc
...
@@ -32,13 +32,14 @@ def main(args):
...
@@ -32,13 +32,14 @@ def main(args):
''' run ansible-playbook operations '''
''' run ansible-playbook operations '''
# create parser for CLI options
# create parser for CLI options
usage
=
"ans-playbook playbook.yml"
usage
=
"ansible-playbook playbook.yml [options]"
parser
=
utils
.
base_parser
(
constants
=
C
,
usage
=
usage
)
options
=
{
parser
.
add_option
(
'-e'
,
'--extra-vars'
,
dest
=
'extra_vars'
,
'-e'
:
dict
(
long
=
'--extra-vars'
,
dest
=
'extra_vars'
,
help
=
'pass in extra key=value variables from outside the playbook'
)
help
=
'pass in extra key=value variables from outside the playbook'
),
parser
.
add_option
(
'-O'
,
'--override-hosts'
,
dest
=
"override_hosts"
,
default
=
None
,
'-O'
:
dict
(
long
=
'--override-hosts'
,
dest
=
"override_hosts"
,
default
=
None
,
help
=
"run playbook against only hosts, ignorning the inventory file"
)
help
=
"run playbook against only hosts, ignorning the inventory file"
)
}
parser
=
utils
.
make_parser
(
options
,
constants
=
C
,
usage
=
usage
)
options
,
args
=
parser
.
parse_args
(
args
)
options
,
args
=
parser
.
parse_args
(
args
)
if
len
(
args
)
==
0
:
if
len
(
args
)
==
0
:
...
@@ -60,20 +61,13 @@ def main(args):
...
@@ -60,20 +61,13 @@ def main(args):
runner_cb
=
callbacks
.
PlaybookRunnerCallbacks
(
stats
)
runner_cb
=
callbacks
.
PlaybookRunnerCallbacks
(
stats
)
pb
=
ansible
.
playbook
.
PlayBook
(
pb
=
ansible
.
playbook
.
PlayBook
(
playbook
=
playbook
,
playbook
=
playbook
,
module_path
=
options
.
module_path
,
host_list
=
options
.
inventory
,
host_list
=
options
.
inventory
,
override_hosts
=
override_hosts
,
extra_vars
=
options
.
extra_vars
,
extra_vars
=
options
.
extra_vars
,
module_path
=
options
.
module_path
,
forks
=
options
.
forks
,
debug
=
options
.
debug
,
verbose
=
True
,
forks
=
options
.
forks
,
remote_pass
=
sshpass
,
remote_port
=
options
.
remote_port
,
debug
=
options
.
debug
,
callbacks
=
playbook_cb
,
runner_callbacks
=
runner_cb
,
stats
=
stats
,
verbose
=
True
,
remote_pass
=
sshpass
,
remote_port
=
options
.
remote_port
,
callbacks
=
playbook_cb
,
runner_callbacks
=
runner_cb
,
stats
=
stats
,
timeout
=
options
.
timeout
,
timeout
=
options
.
timeout
,
override_hosts
=
override_hosts
,
)
)
try
:
try
:
...
...
lib/ansible/utils.py
View file @
7b9856bc
...
@@ -23,8 +23,7 @@ import shlex
...
@@ -23,8 +23,7 @@ import shlex
import
re
import
re
import
jinja2
import
jinja2
import
yaml
import
yaml
from
optparse
import
OptionParser
import
optparse
try
:
try
:
import
json
import
json
...
@@ -274,41 +273,70 @@ def parse_kv(args):
...
@@ -274,41 +273,70 @@ def parse_kv(args):
options
[
k
]
=
v
options
[
k
]
=
v
return
options
return
options
def
base_parser
(
constants
=
C
,
usage
=
""
,
output_opts
=
False
,
runas_opts
=
False
,
async_opts
=
False
):
def
make_parser
(
add_options
,
constants
=
C
,
usage
=
""
,
output_opts
=
False
,
runas_opts
=
False
,
async_opts
=
False
):
''' create an options parser for any ansible script '''
''' create an options parser w/ common options for any ansible program '''
parser
=
OptionParser
(
usage
)
options
=
base_parser_options
(
parser
.
add_option
(
'-D'
,
'--debug'
,
default
=
False
,
action
=
"store_true"
,
constants
=
constants
,
help
=
'enable standard error debugging of modules.'
)
output_opts
=
output_opts
,
parser
.
add_option
(
'-f'
,
'--forks'
,
dest
=
'forks'
,
default
=
constants
.
DEFAULT_FORKS
,
type
=
'int'
,
runas_opts
=
runas_opts
,
help
=
'number of parallel processes to use'
)
async_opts
=
async_opts
parser
.
add_option
(
'-i'
,
'--inventory-file'
,
dest
=
'inventory'
,
)
help
=
'inventory host file'
,
default
=
constants
.
DEFAULT_HOST_LIST
)
options
.
update
(
add_options
)
parser
.
add_option
(
'-k'
,
'--ask-pass'
,
default
=
False
,
action
=
'store_true'
,
help
=
'ask for SSH password'
)
parser
=
optparse
.
OptionParser
()
parser
.
add_option
(
'-M'
,
'--module-path'
,
dest
=
'module_path'
,
names
=
sorted
(
options
.
keys
())
help
=
"path to module library"
,
default
=
constants
.
DEFAULT_MODULE_PATH
)
for
n
in
names
:
parser
.
add_option
(
'-T'
,
'--timeout'
,
default
=
constants
.
DEFAULT_TIMEOUT
,
type
=
'int'
,
data
=
options
[
n
]
.
copy
()
dest
=
'timeout'
,
help
=
'set the SSH timeout in seconds'
)
long
=
data
[
'long'
]
parser
.
add_option
(
'-p'
,
'--port'
,
default
=
constants
.
DEFAULT_REMOTE_PORT
,
type
=
'int'
,
del
data
[
'long'
]
dest
=
'remote_port'
,
help
=
'set the remote ssh port'
)
parser
.
add_option
(
n
,
long
,
**
data
)
return
parser
def
base_parser_options
(
constants
=
C
,
output_opts
=
False
,
runas_opts
=
False
,
async_opts
=
False
):
''' creates common options for ansible programs '''
options
=
{
'-D'
:
dict
(
long
=
'--debug'
,
default
=
False
,
action
=
"store_true"
,
help
=
'show debug/verbose module output'
),
'-f'
:
dict
(
long
=
'--forks'
,
dest
=
'forks'
,
default
=
constants
.
DEFAULT_FORKS
,
type
=
'int'
,
help
=
'number of parallel processes to use'
),
'-i'
:
dict
(
long
=
'--inventory-file'
,
dest
=
'inventory'
,
help
=
'path to inventory host file'
,
default
=
constants
.
DEFAULT_HOST_LIST
),
'-k'
:
dict
(
long
=
'--ask-pass'
,
default
=
False
,
action
=
'store_true'
,
help
=
'ask for SSH password'
),
'-M'
:
dict
(
long
=
'--module-path'
,
dest
=
'module_path'
,
help
=
"path to module library directory"
,
default
=
constants
.
DEFAULT_MODULE_PATH
),
'-T'
:
dict
(
long
=
'--timeout'
,
default
=
constants
.
DEFAULT_TIMEOUT
,
type
=
'int'
,
dest
=
'timeout'
,
help
=
'set the SSH connection timeout in seconds'
),
'-p'
:
dict
(
long
=
'--port'
,
default
=
constants
.
DEFAULT_REMOTE_PORT
,
type
=
'int'
,
dest
=
'remote_port'
,
help
=
'use this remote SSH port'
),
}
if
output_opts
:
if
output_opts
:
parser
.
add_option
(
'-o'
,
'--one-line'
,
dest
=
'one_line'
,
action
=
'store_true'
,
options
.
update
({
help
=
'condense output'
)
'-o'
:
dict
(
long
=
'--one-line'
,
dest
=
'one_line'
,
action
=
'store_true'
,
parser
.
add_option
(
'-t'
,
'--tree'
,
dest
=
'tree'
,
default
=
None
,
help
=
'condense output'
),
help
=
'log output to this directory'
)
'-t'
:
dict
(
long
=
'--tree'
,
dest
=
'tree'
,
default
=
None
,
help
=
'log results to this directory'
)
})
if
runas_opts
:
if
runas_opts
:
parser
.
add_option
(
"-s"
,
"--sudo"
,
default
=
False
,
action
=
"store_true"
,
options
.
update
({
dest
=
'sudo'
,
help
=
"run operations with sudo (nopasswd)"
)
'-s'
:
dict
(
long
=
"--sudo"
,
default
=
False
,
action
=
"store_true"
,
parser
.
add_option
(
'-u'
,
'--user'
,
default
=
constants
.
DEFAULT_REMOTE_USER
,
dest
=
'sudo'
,
help
=
"run operations with sudo (nopasswd)"
),
dest
=
'remote_user'
,
help
=
'connect as this user'
)
'-u'
:
dict
(
long
=
'--user'
,
default
=
constants
.
DEFAULT_REMOTE_USER
,
dest
=
'remote_user'
,
help
=
'connect as this user'
),
})
if
async_opts
:
if
async_opts
:
parser
.
add_option
(
'-P'
,
'--poll'
,
default
=
constants
.
DEFAULT_POLL_INTERVAL
,
type
=
'int'
,
options
.
update
({
dest
=
'poll_interval'
,
help
=
'set the poll interval if using -B'
)
'-P'
:
dict
(
long
=
'--poll'
,
default
=
constants
.
DEFAULT_POLL_INTERVAL
,
type
=
'int'
,
parser
.
add_option
(
'-B'
,
'--background'
,
dest
=
'seconds'
,
type
=
'int'
,
default
=
0
,
dest
=
'poll_interval'
,
help
=
'set the poll interval if using -B'
),
help
=
'run asynchronously, failing after X seconds'
)
'-B'
:
dict
(
long
=
'--background'
,
dest
=
'seconds'
,
type
=
'int'
,
default
=
0
,
help
=
'run asynchronously, failing after X seconds'
),
})
return
options
return
parser
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment