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
68358e31
Commit
68358e31
authored
Sep 18, 2014
by
Matt Martz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow ansible (ad-hoc) to support --extra-vars also
parent
9fe0b883
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
16 deletions
+24
-16
bin/ansible
+4
-1
bin/ansible-playbook
+1
-15
bin/ansible-pull
+2
-0
lib/ansible/utils/__init__.py
+17
-0
No files found.
bin/ansible
View file @
68358e31
...
@@ -120,6 +120,8 @@ class Cli(object):
...
@@ -120,6 +120,8 @@ class Cli(object):
if
not
options
.
ask_vault_pass
and
options
.
vault_password_file
:
if
not
options
.
ask_vault_pass
and
options
.
vault_password_file
:
vault_pass
=
utils
.
read_vault_file
(
options
.
vault_password_file
)
vault_pass
=
utils
.
read_vault_file
(
options
.
vault_password_file
)
extra_vars
=
utils
.
parse_extra_vars
(
options
.
extra_vars
,
vault_pass
)
inventory_manager
=
inventory
.
Inventory
(
options
.
inventory
,
vault_password
=
vault_pass
)
inventory_manager
=
inventory
.
Inventory
(
options
.
inventory
,
vault_password
=
vault_pass
)
if
options
.
subset
:
if
options
.
subset
:
inventory_manager
.
subset
(
options
.
subset
)
inventory_manager
.
subset
(
options
.
subset
)
...
@@ -168,7 +170,8 @@ class Cli(object):
...
@@ -168,7 +170,8 @@ class Cli(object):
su
=
options
.
su
,
su
=
options
.
su
,
su_pass
=
su_pass
,
su_pass
=
su_pass
,
su_user
=
options
.
su_user
,
su_user
=
options
.
su_user
,
vault_pass
=
vault_pass
vault_pass
=
vault_pass
,
extra_vars
=
extra_vars
,
)
)
if
options
.
seconds
:
if
options
.
seconds
:
...
...
bin/ansible-playbook
View file @
68358e31
...
@@ -47,7 +47,6 @@ import ansible.utils.template
...
@@ -47,7 +47,6 @@ import ansible.utils.template
from
ansible
import
errors
from
ansible
import
errors
from
ansible
import
callbacks
from
ansible
import
callbacks
from
ansible
import
utils
from
ansible
import
utils
from
ansible.utils
import
to_unicode
from
ansible.color
import
ANSIBLE_COLOR
,
stringc
from
ansible.color
import
ANSIBLE_COLOR
,
stringc
from
ansible.callbacks
import
display
from
ansible.callbacks
import
display
...
@@ -84,8 +83,6 @@ def main(args):
...
@@ -84,8 +83,6 @@ def main(args):
)
)
#parser.add_option('--vault-password', dest="vault_password",
#parser.add_option('--vault-password', dest="vault_password",
# help="password for vault encrypted files")
# help="password for vault encrypted files")
parser
.
add_option
(
'-e'
,
'--extra-vars'
,
dest
=
"extra_vars"
,
action
=
"append"
,
help
=
"set additional variables as key=value or YAML/JSON"
,
default
=
[])
parser
.
add_option
(
'-t'
,
'--tags'
,
dest
=
'tags'
,
default
=
'all'
,
parser
.
add_option
(
'-t'
,
'--tags'
,
dest
=
'tags'
,
default
=
'all'
,
help
=
"only run plays and tasks tagged with these values"
)
help
=
"only run plays and tasks tagged with these values"
)
parser
.
add_option
(
'--skip-tags'
,
dest
=
'skip_tags'
,
parser
.
add_option
(
'--skip-tags'
,
dest
=
'skip_tags'
,
...
@@ -143,18 +140,7 @@ def main(args):
...
@@ -143,18 +140,7 @@ def main(args):
if
not
options
.
ask_vault_pass
and
options
.
vault_password_file
:
if
not
options
.
ask_vault_pass
and
options
.
vault_password_file
:
vault_pass
=
utils
.
read_vault_file
(
options
.
vault_password_file
)
vault_pass
=
utils
.
read_vault_file
(
options
.
vault_password_file
)
extra_vars
=
{}
extra_vars
=
utils
.
parse_extra_vars
(
options
.
extra_vars
,
vault_pass
)
for
extra_vars_opt
in
options
.
extra_vars
:
extra_vars_opt
=
to_unicode
(
extra_vars_opt
)
if
extra_vars_opt
.
startswith
(
u"@"
):
# Argument is a YAML file (JSON is a subset of YAML)
extra_vars
=
utils
.
combine_vars
(
extra_vars
,
utils
.
parse_yaml_from_file
(
extra_vars_opt
[
1
:],
vault_password
=
vault_pass
))
elif
extra_vars_opt
and
extra_vars_opt
[
0
]
in
u'[{'
:
# Arguments as YAML
extra_vars
=
utils
.
combine_vars
(
extra_vars
,
utils
.
parse_yaml
(
extra_vars_opt
))
else
:
# Arguments as Key-value
extra_vars
=
utils
.
combine_vars
(
extra_vars
,
utils
.
parse_kv
(
extra_vars_opt
))
only_tags
=
options
.
tags
.
split
(
","
)
only_tags
=
options
.
tags
.
split
(
","
)
skip_tags
=
options
.
skip_tags
skip_tags
=
options
.
skip_tags
...
...
bin/ansible-pull
View file @
68358e31
...
@@ -189,6 +189,8 @@ def main(args):
...
@@ -189,6 +189,8 @@ def main(args):
cmd
=
'ansible localhost -i "
%
s"
%
s -m
%
s -a "
%
s"'
%
(
cmd
=
'ansible localhost -i "
%
s"
%
s -m
%
s -a "
%
s"'
%
(
inv_opts
,
base_opts
,
options
.
module_name
,
repo_opts
inv_opts
,
base_opts
,
options
.
module_name
,
repo_opts
)
)
for
ev
in
options
.
extra_vars
:
cmd
+=
' -e "
%
s"'
%
ev
if
options
.
sleep
:
if
options
.
sleep
:
try
:
try
:
...
...
lib/ansible/utils/__init__.py
View file @
68358e31
...
@@ -978,6 +978,8 @@ def base_parser(constants=C, usage="", output_opts=False, runas_opts=False,
...
@@ -978,6 +978,8 @@ def base_parser(constants=C, usage="", output_opts=False, runas_opts=False,
parser
.
add_option
(
'-i'
,
'--inventory-file'
,
dest
=
'inventory'
,
parser
.
add_option
(
'-i'
,
'--inventory-file'
,
dest
=
'inventory'
,
help
=
"specify inventory host file (default=
%
s)"
%
constants
.
DEFAULT_HOST_LIST
,
help
=
"specify inventory host file (default=
%
s)"
%
constants
.
DEFAULT_HOST_LIST
,
default
=
constants
.
DEFAULT_HOST_LIST
)
default
=
constants
.
DEFAULT_HOST_LIST
)
parser
.
add_option
(
'-e'
,
'--extra-vars'
,
dest
=
"extra_vars"
,
action
=
"append"
,
help
=
"set additional variables as key=value or YAML/JSON"
,
default
=
[])
parser
.
add_option
(
'-k'
,
'--ask-pass'
,
default
=
False
,
dest
=
'ask_pass'
,
action
=
'store_true'
,
parser
.
add_option
(
'-k'
,
'--ask-pass'
,
default
=
False
,
dest
=
'ask_pass'
,
action
=
'store_true'
,
help
=
'ask for SSH password'
)
help
=
'ask for SSH password'
)
parser
.
add_option
(
'--private-key'
,
default
=
C
.
DEFAULT_PRIVATE_KEY_FILE
,
dest
=
'private_key_file'
,
parser
.
add_option
(
'--private-key'
,
default
=
C
.
DEFAULT_PRIVATE_KEY_FILE
,
dest
=
'private_key_file'
,
...
@@ -1048,6 +1050,21 @@ def base_parser(constants=C, usage="", output_opts=False, runas_opts=False,
...
@@ -1048,6 +1050,21 @@ def base_parser(constants=C, usage="", output_opts=False, runas_opts=False,
return
parser
return
parser
def
parse_extra_vars
(
extra_vars_opts
,
vault_pass
):
extra_vars
=
{}
for
extra_vars_opt
in
extra_vars_opts
:
extra_vars_opt
=
to_unicode
(
extra_vars_opt
)
if
extra_vars_opt
.
startswith
(
u"@"
):
# Argument is a YAML file (JSON is a subset of YAML)
extra_vars
=
combine_vars
(
extra_vars
,
parse_yaml_from_file
(
extra_vars_opt
[
1
:],
vault_password
=
vault_pass
))
elif
extra_vars_opt
and
extra_vars_opt
[
0
]
in
u'[{'
:
# Arguments as YAML
extra_vars
=
combine_vars
(
extra_vars
,
parse_yaml
(
extra_vars_opt
))
else
:
# Arguments as Key-value
extra_vars
=
combine_vars
(
extra_vars
,
parse_kv
(
extra_vars_opt
))
return
extra_vars
def
ask_vault_passwords
(
ask_vault_pass
=
False
,
ask_new_vault_pass
=
False
,
confirm_vault
=
False
,
confirm_new
=
False
):
def
ask_vault_passwords
(
ask_vault_pass
=
False
,
ask_new_vault_pass
=
False
,
confirm_vault
=
False
,
confirm_new
=
False
):
vault_pass
=
None
vault_pass
=
None
...
...
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