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
adf1492d
Commit
adf1492d
authored
Mar 12, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add external vars example
parent
e582bd5e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
3 deletions
+22
-3
examples/external_vars.yml
+3
-0
examples/playbook.yml
+2
-0
lib/ansible/playbook.py
+17
-3
No files found.
examples/external_vars.yml
0 → 100644
View file @
adf1492d
---
alpha
:
one
beta
:
two
examples/playbook.yml
View file @
adf1492d
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
vars
:
vars
:
http_port
:
80
http_port
:
80
max_clients
:
200
max_clients
:
200
vars_files
:
-
external_vars.yml
tasks
:
tasks
:
-
name
:
simulate long running op (15 sec), wait for up to 45, poll every 5
-
name
:
simulate long running op (15 sec), wait for up to 45, poll every 5
action
:
command /bin/sleep 15
action
:
command /bin/sleep 15
...
...
lib/ansible/playbook.py
View file @
adf1492d
...
@@ -85,12 +85,25 @@ class PlayBook(object):
...
@@ -85,12 +85,25 @@ class PlayBook(object):
self
.
basedir
=
os
.
path
.
dirname
(
playbook
)
self
.
basedir
=
os
.
path
.
dirname
(
playbook
)
self
.
playbook
=
self
.
_parse_playbook
(
playbook
)
self
.
playbook
=
self
.
_parse_playbook
(
playbook
)
def
_get_vars
(
self
,
play
,
dirname
):
vars
=
play
.
get
(
'vars'
,
{})
vars_files
=
play
.
get
(
'vars_files'
,
[])
for
f
in
vars_files
:
path
=
path_dwim
(
dirname
,
f
)
# FIXME: better error handling if not valid YAML
# or file not found
# raise typed exception
data
=
file
(
path
)
.
read
()
data
=
yaml
.
load
(
data
)
vars
.
update
(
data
)
return
vars
def
_include_tasks
(
self
,
play
,
task
,
dirname
,
new_tasks
):
def
_include_tasks
(
self
,
play
,
task
,
dirname
,
new_tasks
):
# an include line looks like:
# an include line looks like:
# include: some.yml a=2 b=3 c=4
# include: some.yml a=2 b=3 c=4
include_tokens
=
task
[
'include'
]
.
split
()
include_tokens
=
task
[
'include'
]
.
split
()
path
=
path_dwim
(
dirname
,
include_tokens
[
0
])
path
=
path_dwim
(
dirname
,
include_tokens
[
0
])
inject_vars
=
play
.
get
(
'vars'
,
{}
)
inject_vars
=
self
.
_get_vars
(
play
,
dirname
)
for
i
,
x
in
enumerate
(
include_tokens
):
for
i
,
x
in
enumerate
(
include_tokens
):
if
x
.
find
(
"="
)
!=
-
1
:
if
x
.
find
(
"="
)
!=
-
1
:
(
k
,
v
)
=
x
.
split
(
"="
)
(
k
,
v
)
=
x
.
split
(
"="
)
...
@@ -105,7 +118,7 @@ class PlayBook(object):
...
@@ -105,7 +118,7 @@ class PlayBook(object):
def
_include_handlers
(
self
,
play
,
handler
,
dirname
,
new_handlers
):
def
_include_handlers
(
self
,
play
,
handler
,
dirname
,
new_handlers
):
path
=
path_dwim
(
dirname
,
handler
[
'include'
])
path
=
path_dwim
(
dirname
,
handler
[
'include'
])
included
=
file
(
path
)
.
read
()
included
=
file
(
path
)
.
read
()
inject_vars
=
play
.
get
(
'vars'
,
{}
)
inject_vars
=
self
.
_get_vars
(
play
,
dirname
)
template
=
jinja2
.
Template
(
included
)
template
=
jinja2
.
Template
(
included
)
included
=
template
.
render
(
inject_vars
)
included
=
template
.
render
(
inject_vars
)
included
=
yaml
.
load
(
included
)
included
=
yaml
.
load
(
included
)
...
@@ -383,7 +396,8 @@ class PlayBook(object):
...
@@ -383,7 +396,8 @@ class PlayBook(object):
# get configuration information about the pattern
# get configuration information about the pattern
pattern
=
pg
[
'hosts'
]
pattern
=
pg
[
'hosts'
]
vars
=
pg
.
get
(
'vars'
,
{})
vars
=
self
.
_get_vars
(
pg
,
self
.
basedir
)
tasks
=
pg
[
'tasks'
]
tasks
=
pg
[
'tasks'
]
handlers
=
pg
[
'handlers'
]
handlers
=
pg
[
'handlers'
]
user
=
pg
.
get
(
'user'
,
C
.
DEFAULT_REMOTE_USER
)
user
=
pg
.
get
(
'user'
,
C
.
DEFAULT_REMOTE_USER
)
...
...
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