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
4ee4ddcd
Commit
4ee4ddcd
authored
Mar 05, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parameterized include statements can see top level variables and also be passed specific variables!
Code needs cleanup, but works
parent
fb3bfa1c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
3 deletions
+18
-3
examples/base.yml
+2
-0
examples/playbook.yml
+1
-1
lib/ansible/playbook.py
+15
-2
No files found.
examples/base.yml
View file @
4ee4ddcd
...
...
@@ -3,3 +3,5 @@
action
:
command /usr/sbin/setenforce 0
-
name
:
no iptables
action
:
service name=iptables state=stopped
-
name
:
this is just to show variables work here, favcolor={{ favcolor }}
action
:
command /bin/true
examples/playbook.yml
View file @
4ee4ddcd
...
...
@@ -5,7 +5,7 @@
http_port
:
80
max_clients
:
200
tasks
:
-
include
:
base.yml
-
include
:
base.yml
favcolor=blue
-
name
:
write the apache config file using vars set above
action
:
template src=/srv/httpd.j2 dest=/etc/httpd.conf
notify
:
...
...
lib/ansible/playbook.py
View file @
4ee4ddcd
...
...
@@ -23,6 +23,7 @@ from ansible.utils import *
import
yaml
import
shlex
import
os
import
jinja2
SETUP_CACHE
=
{
'foo'
:
{}
}
...
...
@@ -92,8 +93,20 @@ class PlayBook(object):
new_tasks
=
[]
for
task
in
tasks
:
if
'include'
in
task
:
path
=
path_dwim
(
dirname
,
task
[
'include'
])
included
=
yaml
.
load
(
file
(
path
)
.
read
())
# FIXME: refactor
# an include line looks like:
# include: some.yml a=2 b=3 c=4
include_tokens
=
task
[
'include'
]
.
split
()
path
=
path_dwim
(
dirname
,
include_tokens
[
0
])
inject_vars
=
play
.
get
(
'vars'
,
{})
for
i
,
x
in
enumerate
(
include_tokens
):
if
x
.
find
(
"="
)
!=
-
1
:
(
k
,
v
)
=
x
.
split
(
"="
)
inject_vars
[
k
]
=
v
included
=
file
(
path
)
.
read
()
template
=
jinja2
.
Template
(
included
)
included
=
template
.
render
(
inject_vars
)
included
=
yaml
.
load
(
included
)
for
x
in
included
:
new_tasks
.
append
(
x
)
else
:
...
...
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