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
68a9adc1
Commit
68a9adc1
authored
Jul 15, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Indentation cleanup (partial)
parent
7b177e8e
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
45 additions
and
52 deletions
+45
-52
lib/ansible/callbacks.py
+1
-1
lib/ansible/inventory/__init__.py
+6
-7
lib/ansible/inventory/group.py
+2
-2
lib/ansible/inventory/host.py
+1
-1
lib/ansible/inventory/ini.py
+7
-7
lib/ansible/inventory/yaml.py
+3
-3
lib/ansible/playbook/__init__.py
+11
-17
lib/ansible/runner/__init__.py
+12
-12
lib/ansible/utils.py
+2
-2
No files found.
lib/ansible/callbacks.py
View file @
68a9adc1
...
@@ -241,7 +241,7 @@ class PlaybookCallbacks(object):
...
@@ -241,7 +241,7 @@ class PlaybookCallbacks(object):
def
on_task_start
(
self
,
name
,
is_conditional
):
def
on_task_start
(
self
,
name
,
is_conditional
):
msg
=
"TASK: [
%
s]"
%
name
msg
=
"TASK: [
%
s]"
%
name
if
is_conditional
:
if
is_conditional
:
msg
=
"NOTIFIED: [
%
s]"
%
name
msg
=
"NOTIFIED: [
%
s]"
%
name
print
banner
(
msg
)
print
banner
(
msg
)
def
on_vars_prompt
(
self
,
varname
,
private
=
True
):
def
on_vars_prompt
(
self
,
varname
,
private
=
True
):
...
...
lib/ansible/inventory/__init__.py
View file @
68a9adc1
...
@@ -52,7 +52,7 @@ class Inventory(object):
...
@@ -52,7 +52,7 @@ class Inventory(object):
if
type
(
host_list
)
in
[
str
,
unicode
]:
if
type
(
host_list
)
in
[
str
,
unicode
]:
if
host_list
.
find
(
","
)
!=
-
1
:
if
host_list
.
find
(
","
)
!=
-
1
:
host_list
=
host_list
.
split
(
","
)
host_list
=
host_list
.
split
(
","
)
if
type
(
host_list
)
==
list
:
if
type
(
host_list
)
==
list
:
all
=
Group
(
'all'
)
all
=
Group
(
'all'
)
...
@@ -108,8 +108,8 @@ class Inventory(object):
...
@@ -108,8 +108,8 @@ class Inventory(object):
def
get_host
(
self
,
hostname
):
def
get_host
(
self
,
hostname
):
for
group
in
self
.
groups
:
for
group
in
self
.
groups
:
for
host
in
group
.
get_hosts
():
for
host
in
group
.
get_hosts
():
if
hostname
==
host
.
name
:
if
hostname
==
host
.
name
:
return
host
return
host
return
None
return
None
...
@@ -161,10 +161,9 @@ class Inventory(object):
...
@@ -161,10 +161,9 @@ class Inventory(object):
def
restrict_to
(
self
,
restriction
,
append_missing
=
False
):
def
restrict_to
(
self
,
restriction
,
append_missing
=
False
):
""" Restrict list operations to the hosts given in restriction """
""" Restrict list operations to the hosts given in restriction """
if
type
(
restriction
)
!=
list
:
if
type
(
restriction
)
!=
list
:
restriction
=
[
restriction
]
restriction
=
[
restriction
]
self
.
_restriction
=
restriction
self
.
_restriction
=
restriction
def
lift_restriction
(
self
):
def
lift_restriction
(
self
):
""" Do not restrict list operations """
""" Do not restrict list operations """
...
...
lib/ansible/inventory/group.py
View file @
68a9adc1
...
@@ -31,7 +31,7 @@ class Group(object):
...
@@ -31,7 +31,7 @@ class Group(object):
self
.
child_groups
=
[]
self
.
child_groups
=
[]
self
.
parent_groups
=
[]
self
.
parent_groups
=
[]
if
self
.
name
is
None
:
if
self
.
name
is
None
:
raise
Exception
(
"group name is required"
)
raise
Exception
(
"group name is required"
)
def
add_child_group
(
self
,
group
):
def
add_child_group
(
self
,
group
):
if
self
==
group
:
if
self
==
group
:
...
@@ -57,7 +57,7 @@ class Group(object):
...
@@ -57,7 +57,7 @@ class Group(object):
vars
=
{}
vars
=
{}
# FIXME: verify this variable override order is what we want
# FIXME: verify this variable override order is what we want
for
ancestor
in
self
.
get_ancestors
():
for
ancestor
in
self
.
get_ancestors
():
vars
.
update
(
ancestor
.
get_variables
())
vars
.
update
(
ancestor
.
get_variables
())
vars
.
update
(
self
.
vars
)
vars
.
update
(
self
.
vars
)
return
vars
return
vars
...
...
lib/ansible/inventory/host.py
View file @
68a9adc1
...
@@ -39,7 +39,7 @@ class Host(object):
...
@@ -39,7 +39,7 @@ class Host(object):
self
.
groups
.
append
(
group
)
self
.
groups
.
append
(
group
)
def
set_variable
(
self
,
key
,
value
):
def
set_variable
(
self
,
key
,
value
):
self
.
vars
[
key
]
=
value
;
self
.
vars
[
key
]
=
value
def
get_groups
(
self
):
def
get_groups
(
self
):
groups
=
{}
groups
=
{}
...
...
lib/ansible/inventory/ini.py
View file @
68a9adc1
...
@@ -79,9 +79,9 @@ class InventoryParser(object):
...
@@ -79,9 +79,9 @@ class InventoryParser(object):
hostname
=
tokens
[
0
]
hostname
=
tokens
[
0
]
port
=
C
.
DEFAULT_REMOTE_PORT
port
=
C
.
DEFAULT_REMOTE_PORT
if
hostname
.
find
(
":"
)
!=
-
1
:
if
hostname
.
find
(
":"
)
!=
-
1
:
tokens2
=
hostname
.
split
(
":"
)
tokens2
=
hostname
.
split
(
":"
)
hostname
=
tokens2
[
0
]
hostname
=
tokens2
[
0
]
port
=
tokens2
[
1
]
port
=
tokens2
[
1
]
host
=
None
host
=
None
if
hostname
in
self
.
hosts
:
if
hostname
in
self
.
hosts
:
host
=
self
.
hosts
[
hostname
]
host
=
self
.
hosts
[
hostname
]
...
@@ -89,9 +89,9 @@ class InventoryParser(object):
...
@@ -89,9 +89,9 @@ class InventoryParser(object):
host
=
Host
(
name
=
hostname
,
port
=
port
)
host
=
Host
(
name
=
hostname
,
port
=
port
)
self
.
hosts
[
hostname
]
=
host
self
.
hosts
[
hostname
]
=
host
if
len
(
tokens
)
>
1
:
if
len
(
tokens
)
>
1
:
for
t
in
tokens
[
1
:]:
for
t
in
tokens
[
1
:]:
(
k
,
v
)
=
t
.
split
(
"="
)
(
k
,
v
)
=
t
.
split
(
"="
)
host
.
set_variable
(
k
,
v
)
host
.
set_variable
(
k
,
v
)
self
.
groups
[
active_group_name
]
.
add_host
(
host
)
self
.
groups
[
active_group_name
]
.
add_host
(
host
)
# [southeast:children]
# [southeast:children]
...
@@ -134,7 +134,7 @@ class InventoryParser(object):
...
@@ -134,7 +134,7 @@ class InventoryParser(object):
line
=
line
.
replace
(
"["
,
""
)
.
replace
(
":vars]"
,
""
)
line
=
line
.
replace
(
"["
,
""
)
.
replace
(
":vars]"
,
""
)
group
=
self
.
groups
.
get
(
line
,
None
)
group
=
self
.
groups
.
get
(
line
,
None
)
if
group
is
None
:
if
group
is
None
:
raise
errors
.
AnsibleError
(
"can't add vars to undefined group:
%
s"
%
line
)
raise
errors
.
AnsibleError
(
"can't add vars to undefined group:
%
s"
%
line
)
elif
line
.
startswith
(
"#"
):
elif
line
.
startswith
(
"#"
):
pass
pass
elif
line
.
startswith
(
"["
):
elif
line
.
startswith
(
"["
):
...
...
lib/ansible/inventory/yaml.py
View file @
68a9adc1
...
@@ -73,8 +73,8 @@ class InventoryParserYaml(object):
...
@@ -73,8 +73,8 @@ class InventoryParserYaml(object):
vars
=
subresult
.
get
(
'vars'
,{})
vars
=
subresult
.
get
(
'vars'
,{})
if
type
(
vars
)
==
list
:
if
type
(
vars
)
==
list
:
for
subitem
in
vars
:
for
subitem
in
vars
:
for
(
k
,
v
)
in
subitem
.
items
():
for
(
k
,
v
)
in
subitem
.
items
():
host
.
set_variable
(
k
,
v
)
host
.
set_variable
(
k
,
v
)
elif
type
(
vars
)
==
dict
:
elif
type
(
vars
)
==
dict
:
for
(
k
,
v
)
in
subresult
.
get
(
'vars'
,{})
.
items
():
for
(
k
,
v
)
in
subresult
.
get
(
'vars'
,{})
.
items
():
host
.
set_variable
(
k
,
v
)
host
.
set_variable
(
k
,
v
)
...
@@ -113,7 +113,7 @@ class InventoryParserYaml(object):
...
@@ -113,7 +113,7 @@ class InventoryParserYaml(object):
for
subitem
in
varlist
:
for
subitem
in
varlist
:
vars
.
update
(
subitem
)
vars
.
update
(
subitem
)
for
(
k
,
v
)
in
vars
.
items
():
for
(
k
,
v
)
in
vars
.
items
():
host
.
set_variable
(
k
,
v
)
host
.
set_variable
(
k
,
v
)
groups
=
item
.
get
(
'groups'
,
{})
groups
=
item
.
get
(
'groups'
,
{})
if
type
(
groups
)
in
[
str
,
unicode
]:
if
type
(
groups
)
in
[
str
,
unicode
]:
...
...
lib/ansible/playbook/__init__.py
View file @
68a9adc1
...
@@ -133,25 +133,19 @@ class PlayBook(object):
...
@@ -133,25 +133,19 @@ class PlayBook(object):
accumulated_plays
=
[]
accumulated_plays
=
[]
if
type
(
playbook_data
)
!=
list
:
if
type
(
playbook_data
)
!=
list
:
raise
errors
.
AnsibleError
(
raise
errors
.
AnsibleError
(
"parse error: playbooks must be formatted as a YAML list"
)
"parse error: playbooks must be formatted as a YAML list"
)
for
play
in
playbook_data
:
for
play
in
playbook_data
:
if
type
(
play
)
!=
dict
:
if
type
(
play
)
!=
dict
:
raise
errors
.
AnsibleError
(
raise
errors
.
AnsibleError
(
"parse error: each play in a playbook must a YAML dictionary (hash), recieved:
%
s"
%
play
)
"parse error: each play in a playbook must a YAML dictionary (hash), recieved:
%
s"
%
play
if
'include'
in
play
:
)
if
len
(
play
.
keys
())
==
1
:
if
'include'
in
play
:
included_path
=
utils
.
path_dwim
(
self
.
basedir
,
play
[
'include'
])
if
len
(
play
.
keys
())
==
1
:
accumulated_plays
.
extend
(
self
.
_load_playbook_from_file
(
included_path
))
included_path
=
utils
.
path_dwim
(
self
.
basedir
,
play
[
'include'
])
else
:
accumulated_plays
.
extend
(
self
.
_load_playbook_from_file
(
included_path
))
raise
errors
.
AnsibleError
(
"parse error: top level includes cannot be used with other directives:
%
s"
%
play
)
else
:
else
:
raise
errors
.
AnsibleError
(
accumulated_plays
.
append
(
play
)
"parse error: top level includes cannot be used with other directives:
%
s"
%
play
)
else
:
accumulated_plays
.
append
(
play
)
return
accumulated_plays
return
accumulated_plays
...
...
lib/ansible/runner/__init__.py
View file @
68a9adc1
...
@@ -291,7 +291,7 @@ class Runner(object):
...
@@ -291,7 +291,7 @@ class Runner(object):
break
break
msg
=
'All items succeeded'
msg
=
'All items succeeded'
if
all_failed
:
if
all_failed
:
msg
=
"One or more items failed."
msg
=
"One or more items failed."
rd_result
=
dict
(
rd_result
=
dict
(
failed
=
all_failed
,
failed
=
all_failed
,
changed
=
all_changed
,
changed
=
all_changed
,
...
@@ -345,20 +345,20 @@ class Runner(object):
...
@@ -345,20 +345,20 @@ class Runner(object):
# *****************************************************
# *****************************************************
def
_save_setup_result_to_disk
(
self
,
conn
,
result
):
def
_save_setup_result_to_disk
(
self
,
conn
,
result
):
''' cache results of calling setup '''
''' cache results of calling setup '''
dest
=
os
.
path
.
expanduser
(
"~/.ansible_setup_data"
)
dest
=
os
.
path
.
expanduser
(
"~/.ansible_setup_data"
)
user
=
getpass
.
getuser
()
user
=
getpass
.
getuser
()
if
user
==
'root'
:
if
user
==
'root'
:
dest
=
"/var/lib/ansible/setup_data"
dest
=
"/var/lib/ansible/setup_data"
if
not
os
.
path
.
exists
(
dest
):
if
not
os
.
path
.
exists
(
dest
):
os
.
makedirs
(
dest
)
os
.
makedirs
(
dest
)
fh
=
open
(
os
.
path
.
join
(
dest
,
conn
.
host
),
"w"
)
fh
=
open
(
os
.
path
.
join
(
dest
,
conn
.
host
),
"w"
)
fh
.
write
(
result
)
fh
.
write
(
result
)
fh
.
close
()
fh
.
close
()
return
result
return
result
# *****************************************************
# *****************************************************
...
...
lib/ansible/utils.py
View file @
68a9adc1
...
@@ -177,11 +177,11 @@ def parse_json(data):
...
@@ -177,11 +177,11 @@ def parse_json(data):
# not JSON, but try "Baby JSON" which allows many of our modules to not
# not JSON, but try "Baby JSON" which allows many of our modules to not
# require JSON and makes writing modules in bash much simpler
# require JSON and makes writing modules in bash much simpler
results
=
{}
results
=
{}
try
:
try
:
tokens
=
shlex
.
split
(
data
)
tokens
=
shlex
.
split
(
data
)
except
:
except
:
print
"failed to parse json: "
+
data
print
"failed to parse json: "
+
data
raise
;
raise
for
t
in
tokens
:
for
t
in
tokens
:
if
t
.
find
(
"="
)
==
-
1
:
if
t
.
find
(
"="
)
==
-
1
:
...
...
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