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
b8b20600
Commit
b8b20600
authored
Jul 21, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Generalize extra variable parsing and loading
Fixes #11352
parent
d8b62f3b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
17 deletions
+22
-17
lib/ansible/cli/adhoc.py
+3
-1
lib/ansible/cli/playbook.py
+2
-16
lib/ansible/utils/vars.py
+17
-0
No files found.
lib/ansible/cli/adhoc.py
View file @
b8b20600
...
@@ -17,13 +17,14 @@
...
@@ -17,13 +17,14 @@
########################################################
########################################################
from
ansible
import
constants
as
C
from
ansible
import
constants
as
C
from
ansible.cli
import
CLI
from
ansible.errors
import
AnsibleOptionsError
from
ansible.errors
import
AnsibleOptionsError
from
ansible.executor.task_queue_manager
import
TaskQueueManager
from
ansible.executor.task_queue_manager
import
TaskQueueManager
from
ansible.inventory
import
Inventory
from
ansible.inventory
import
Inventory
from
ansible.parsing
import
DataLoader
from
ansible.parsing
import
DataLoader
from
ansible.parsing.splitter
import
parse_kv
from
ansible.parsing.splitter
import
parse_kv
from
ansible.playbook.play
import
Play
from
ansible.playbook.play
import
Play
from
ansible.
cli
import
CLI
from
ansible.
utils.vars
import
load_extra_vars
from
ansible.vars
import
VariableManager
from
ansible.vars
import
VariableManager
########################################################
########################################################
...
@@ -100,6 +101,7 @@ class AdHocCLI(CLI):
...
@@ -100,6 +101,7 @@ class AdHocCLI(CLI):
loader
=
DataLoader
(
vault_password
=
vault_pass
)
loader
=
DataLoader
(
vault_password
=
vault_pass
)
variable_manager
=
VariableManager
()
variable_manager
=
VariableManager
()
variable_manager
.
extra_vars
=
load_extra_vars
(
loader
=
loader
,
options
=
self
.
options
)
inventory
=
Inventory
(
loader
=
loader
,
variable_manager
=
variable_manager
,
host_list
=
self
.
options
.
inventory
)
inventory
=
Inventory
(
loader
=
loader
,
variable_manager
=
variable_manager
,
host_list
=
self
.
options
.
inventory
)
variable_manager
.
set_inventory
(
inventory
)
variable_manager
.
set_inventory
(
inventory
)
...
...
lib/ansible/cli/playbook.py
View file @
b8b20600
...
@@ -33,7 +33,7 @@ from ansible.playbook import Playbook
...
@@ -33,7 +33,7 @@ from ansible.playbook import Playbook
from
ansible.playbook.task
import
Task
from
ansible.playbook.task
import
Task
from
ansible.utils.display
import
Display
from
ansible.utils.display
import
Display
from
ansible.utils.unicode
import
to_unicode
from
ansible.utils.unicode
import
to_unicode
from
ansible.utils.vars
import
combine
_vars
from
ansible.utils.vars
import
load_extra
_vars
from
ansible.vars
import
VariableManager
from
ansible.vars
import
VariableManager
#---------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------
...
@@ -103,20 +103,6 @@ class PlaybookCLI(CLI):
...
@@ -103,20 +103,6 @@ class PlaybookCLI(CLI):
loader
=
DataLoader
(
vault_password
=
vault_pass
)
loader
=
DataLoader
(
vault_password
=
vault_pass
)
extra_vars
=
{}
for
extra_vars_opt
in
self
.
options
.
extra_vars
:
extra_vars_opt
=
to_unicode
(
extra_vars_opt
,
errors
=
'strict'
)
if
extra_vars_opt
.
startswith
(
u"@"
):
# Argument is a YAML file (JSON is a subset of YAML)
data
=
loader
.
load_from_file
(
extra_vars_opt
[
1
:])
elif
extra_vars_opt
and
extra_vars_opt
[
0
]
in
u'[{'
:
# Arguments as YAML
data
=
loader
.
load
(
extra_vars_opt
)
else
:
# Arguments as Key-value
data
=
parse_kv
(
extra_vars_opt
)
extra_vars
=
combine_vars
(
extra_vars
,
data
)
# FIXME: this should be moved inside the playbook executor code
# FIXME: this should be moved inside the playbook executor code
only_tags
=
self
.
options
.
tags
.
split
(
","
)
only_tags
=
self
.
options
.
tags
.
split
(
","
)
skip_tags
=
self
.
options
.
skip_tags
skip_tags
=
self
.
options
.
skip_tags
...
@@ -134,7 +120,7 @@ class PlaybookCLI(CLI):
...
@@ -134,7 +120,7 @@ class PlaybookCLI(CLI):
# create the variable manager, which will be shared throughout
# create the variable manager, which will be shared throughout
# the code, ensuring a consistent view of global variables
# the code, ensuring a consistent view of global variables
variable_manager
=
VariableManager
()
variable_manager
=
VariableManager
()
variable_manager
.
extra_vars
=
extra_vars
variable_manager
.
extra_vars
=
load_extra_vars
(
loader
=
loader
,
options
=
self
.
options
)
# create the inventory, and filter it based on the subset specified (if any)
# create the inventory, and filter it based on the subset specified (if any)
inventory
=
Inventory
(
loader
=
loader
,
variable_manager
=
variable_manager
,
host_list
=
self
.
options
.
inventory
)
inventory
=
Inventory
(
loader
=
loader
,
variable_manager
=
variable_manager
,
host_list
=
self
.
options
.
inventory
)
...
...
lib/ansible/utils/vars.py
View file @
b8b20600
...
@@ -21,6 +21,8 @@ __metaclass__ = type
...
@@ -21,6 +21,8 @@ __metaclass__ = type
from
ansible
import
constants
as
C
from
ansible
import
constants
as
C
from
ansible.parsing.splitter
import
parse_kv
from
ansible.utils.unicode
import
to_unicode
def
combine_vars
(
a
,
b
):
def
combine_vars
(
a
,
b
):
...
@@ -49,3 +51,18 @@ def merge_hash(a, b):
...
@@ -49,3 +51,18 @@ def merge_hash(a, b):
return
result
return
result
def
load_extra_vars
(
loader
,
options
):
extra_vars
=
{}
for
extra_vars_opt
in
options
.
extra_vars
:
extra_vars_opt
=
to_unicode
(
extra_vars_opt
,
errors
=
'strict'
)
if
extra_vars_opt
.
startswith
(
u"@"
):
# Argument is a YAML file (JSON is a subset of YAML)
data
=
loader
.
load_from_file
(
extra_vars_opt
[
1
:])
elif
extra_vars_opt
and
extra_vars_opt
[
0
]
in
u'[{'
:
# Arguments as YAML
data
=
loader
.
load
(
extra_vars_opt
)
else
:
# Arguments as Key-value
data
=
parse_kv
(
extra_vars_opt
)
extra_vars
=
combine_vars
(
extra_vars
,
data
)
return
extra_vars
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