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
0b6fadaa
Commit
0b6fadaa
authored
Jul 26, 2015
by
Brian Coca
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
started implementing diff
diff now works with template also fixed check mode for template and copy
parent
d11e07a0
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
73 additions
and
54 deletions
+73
-54
lib/ansible/constants.py
+1
-0
lib/ansible/playbook/play_context.py
+3
-0
lib/ansible/plugins/action/__init__.py
+1
-2
lib/ansible/plugins/action/copy.py
+10
-15
lib/ansible/plugins/action/template.py
+37
-30
lib/ansible/plugins/callback/__init__.py
+10
-3
lib/ansible/plugins/strategies/__init__.py
+6
-3
lib/ansible/utils/display.py
+5
-1
No files found.
lib/ansible/constants.py
View file @
0b6fadaa
...
@@ -237,3 +237,4 @@ DEFAULT_SUBSET = None
...
@@ -237,3 +237,4 @@ DEFAULT_SUBSET = None
DEFAULT_SU_PASS
=
None
DEFAULT_SU_PASS
=
None
VAULT_VERSION_MIN
=
1.0
VAULT_VERSION_MIN
=
1.0
VAULT_VERSION_MAX
=
1.0
VAULT_VERSION_MAX
=
1.0
MAX_FILE_SIZE_FOR_DIFF
=
1
*
1024
*
1024
lib/ansible/playbook/play_context.py
View file @
0b6fadaa
...
@@ -175,6 +175,7 @@ class PlayContext(Base):
...
@@ -175,6 +175,7 @@ class PlayContext(Base):
_force_handlers
=
FieldAttribute
(
isa
=
'bool'
,
default
=
False
)
_force_handlers
=
FieldAttribute
(
isa
=
'bool'
,
default
=
False
)
_start_at_task
=
FieldAttribute
(
isa
=
'string'
)
_start_at_task
=
FieldAttribute
(
isa
=
'string'
)
_step
=
FieldAttribute
(
isa
=
'bool'
,
default
=
False
)
_step
=
FieldAttribute
(
isa
=
'bool'
,
default
=
False
)
_diff
=
FieldAttribute
(
isa
=
'bool'
,
default
=
False
)
def
__init__
(
self
,
play
=
None
,
options
=
None
,
passwords
=
None
):
def
__init__
(
self
,
play
=
None
,
options
=
None
,
passwords
=
None
):
...
@@ -253,6 +254,8 @@ class PlayContext(Base):
...
@@ -253,6 +254,8 @@ class PlayContext(Base):
self
.
step
=
boolean
(
options
.
step
)
self
.
step
=
boolean
(
options
.
step
)
if
hasattr
(
options
,
'start_at_task'
)
and
options
.
start_at_task
:
if
hasattr
(
options
,
'start_at_task'
)
and
options
.
start_at_task
:
self
.
start_at_task
=
to_unicode
(
options
.
start_at_task
)
self
.
start_at_task
=
to_unicode
(
options
.
start_at_task
)
if
hasattr
(
options
,
'diff'
)
and
options
.
diff
:
self
.
diff
=
boolean
(
options
.
diff
)
# get the tag info from options, converting a comma-separated list
# get the tag info from options, converting a comma-separated list
# of values into a proper list if need be. We check to see if the
# of values into a proper list if need be. We check to see if the
...
...
lib/ansible/plugins/action/__init__.py
View file @
0b6fadaa
...
@@ -233,8 +233,7 @@ class ActionBase:
...
@@ -233,8 +233,7 @@ class ActionBase:
Takes a remote checksum and returns 1 if no file
Takes a remote checksum and returns 1 if no file
'''
'''
# FIXME: figure out how this will work, probably pulled from the
# FIXME: figure out how this will work, probably pulled from the variable manager data
# variable manager data
#python_interp = inject['hostvars'][inject['inventory_hostname']].get('ansible_python_interpreter', 'python')
#python_interp = inject['hostvars'][inject['inventory_hostname']].get('ansible_python_interpreter', 'python')
python_interp
=
'python'
python_interp
=
'python'
cmd
=
self
.
_connection
.
_shell
.
checksum
(
path
,
python_interp
)
cmd
=
self
.
_connection
.
_shell
.
checksum
(
path
,
python_interp
)
...
...
lib/ansible/plugins/action/copy.py
View file @
0b6fadaa
...
@@ -174,17 +174,11 @@ class ActionModule(ActionBase):
...
@@ -174,17 +174,11 @@ class ActionModule(ActionBase):
if
tmp
is
None
or
"-tmp-"
not
in
tmp
:
if
tmp
is
None
or
"-tmp-"
not
in
tmp
:
tmp
=
self
.
_make_tmp_path
()
tmp
=
self
.
_make_tmp_path
()
# FIXME: runner shouldn't have the diff option there
if
self
.
_play_context
.
diff
and
not
raw
:
#if self.runner.diff and not raw:
diffs
.
append
(
self
.
_get_diff_data
(
tmp
,
dest_file
,
source_full
,
task_vars
))
# diff = self._get_diff_data(tmp, dest_file, source_full, task_vars)
#else:
# diff = {}
diff
=
{}
if
self
.
_play_context
.
check_mode
:
if
self
.
_play_context
.
check_mode
:
self
.
_remove_tempfile_if_content_defined
(
content
,
content_tempfile
)
self
.
_remove_tempfile_if_content_defined
(
content
,
content_tempfile
)
# FIXME: diff stuff
#diffs.append(diff)
changed
=
True
changed
=
True
module_return
=
dict
(
changed
=
True
)
module_return
=
dict
(
changed
=
True
)
continue
continue
...
@@ -231,7 +225,7 @@ class ActionModule(ActionBase):
...
@@ -231,7 +225,7 @@ class ActionModule(ActionBase):
if
raw
:
if
raw
:
# Continue to next iteration if raw is defined.
# Continue to next iteration if raw is defined.
#
self._remove_tmp_path(tmp)
self
.
_remove_tmp_path
(
tmp
)
continue
continue
# Build temporary module_args.
# Build temporary module_args.
...
@@ -244,6 +238,9 @@ class ActionModule(ActionBase):
...
@@ -244,6 +238,9 @@ class ActionModule(ActionBase):
)
)
)
)
if
self
.
_play_context
.
check_mode
:
new_module_args
[
'CHECKMODE'
]
=
True
# Execute the file module.
# Execute the file module.
module_return
=
self
.
_execute_module
(
module_name
=
'file'
,
module_args
=
new_module_args
,
task_vars
=
task_vars
,
delete_remote_tmp
=
delete_remote_tmp
)
module_return
=
self
.
_execute_module
(
module_name
=
'file'
,
module_args
=
new_module_args
,
task_vars
=
task_vars
,
delete_remote_tmp
=
delete_remote_tmp
)
module_executed
=
True
module_executed
=
True
...
@@ -299,9 +296,8 @@ class ActionModule(ActionBase):
...
@@ -299,9 +296,8 @@ class ActionModule(ActionBase):
diff
[
'before'
]
=
''
diff
[
'before'
]
=
''
elif
peek_result
[
'appears_binary'
]:
elif
peek_result
[
'appears_binary'
]:
diff
[
'dst_binary'
]
=
1
diff
[
'dst_binary'
]
=
1
# FIXME: this should not be in utils..
elif
peek_result
[
'size'
]
>
C
.
MAX_FILE_SIZE_FOR_DIFF
:
#elif peek_result['size'] > utils.MAX_FILE_SIZE_FOR_DIFF:
diff
[
'dst_larger'
]
=
C
.
MAX_FILE_SIZE_FOR_DIFF
# diff['dst_larger'] = utils.MAX_FILE_SIZE_FOR_DIFF
else
:
else
:
dest_result
=
self
.
_execute_module
(
module_name
=
'slurp'
,
module_args
=
dict
(
path
=
destination
),
task_vars
=
task_vars
,
tmp
=
tmp
,
persist_files
=
True
)
dest_result
=
self
.
_execute_module
(
module_name
=
'slurp'
,
module_args
=
dict
(
path
=
destination
),
task_vars
=
task_vars
,
tmp
=
tmp
,
persist_files
=
True
)
if
'content'
in
dest_result
:
if
'content'
in
dest_result
:
...
@@ -318,9 +314,8 @@ class ActionModule(ActionBase):
...
@@ -318,9 +314,8 @@ class ActionModule(ActionBase):
st
=
os
.
stat
(
source
)
st
=
os
.
stat
(
source
)
if
"
\x00
"
in
src_contents
:
if
"
\x00
"
in
src_contents
:
diff
[
'src_binary'
]
=
1
diff
[
'src_binary'
]
=
1
# FIXME: this should not be in utils
elif
st
[
stat
.
ST_SIZE
]
>
C
.
MAX_FILE_SIZE_FOR_DIFF
:
#elif st[stat.ST_SIZE] > utils.MAX_FILE_SIZE_FOR_DIFF:
diff
[
'src_larger'
]
=
C
.
MAX_FILE_SIZE_FOR_DIFF
# diff['src_larger'] = utils.MAX_FILE_SIZE_FOR_DIFF
else
:
else
:
src
.
seek
(
0
)
src
.
seek
(
0
)
diff
[
'after_header'
]
=
source
diff
[
'after_header'
]
=
source
...
...
lib/ansible/plugins/action/template.py
View file @
0b6fadaa
...
@@ -125,40 +125,44 @@ class ActionModule(ActionBase):
...
@@ -125,40 +125,44 @@ class ActionModule(ActionBase):
return
remote_checksum
return
remote_checksum
if
local_checksum
!=
remote_checksum
:
if
local_checksum
!=
remote_checksum
:
# if showing diffs, we need to get the remote value
dest_contents
=
''
dest_contents
=
''
# FIXME: still need to implement diff mechanism
# if showing diffs, we need to get the remote value
#if self.runner.diff:
if
self
.
_play_context
.
diff
:
# # using persist_files to keep the temp directory around to avoid needing to grab another
# using persist_files to keep the temp directory around to avoid needing to grab another
# dest_result = self.runner._execute_module(conn, tmp, 'slurp', "path=%s" % dest, task_vars=task_vars, persist_files=True)
my_args
=
dict
(
path
=
dest
)
# if 'content' in dest_result.result:
dest_result
=
self
.
_execute_module
(
module_name
=
'slurp'
,
module_args
=
my_args
,
task_vars
=
task_vars
,
persist_files
=
True
)
# dest_contents = dest_result.result['content']
if
'content'
in
dest_result
:
# if dest_result.result['encoding'] == 'base64':
dest_contents
=
dest_result
[
'content'
]
# dest_contents = base64.b64decode(dest_contents)
if
dest_result
[
'encoding'
]
==
'base64'
:
# else:
dest_contents
=
base64
.
b64decode
(
dest_contents
)
# raise Exception("unknown encoding, failed: %s" % dest_result.result)
else
:
raise
Exception
(
"unknown encoding, failed:
%
s"
%
dest_result
)
xfered
=
self
.
_transfer_data
(
self
.
_connection
.
_shell
.
join_path
(
tmp
,
'source'
),
resultant
)
if
not
self
.
_play_context
.
check_mode
:
# do actual work thorugh copy
# fix file permissions when the copy is done as a different user
xfered
=
self
.
_transfer_data
(
self
.
_connection
.
_shell
.
join_path
(
tmp
,
'source'
),
resultant
)
if
self
.
_play_context
.
become
and
self
.
_play_context
.
become_user
!=
'root'
:
self
.
_remote_chmod
(
'a+r'
,
xfered
,
tmp
)
# fix file permissions when the copy is done as a different user
if
self
.
_play_context
.
become
and
self
.
_play_context
.
become_user
!=
'root'
:
self
.
_remote_chmod
(
'a+r'
,
xfered
,
tmp
)
# run the copy module
new_module_args
=
self
.
_task
.
args
.
copy
()
new_module_args
.
update
(
dict
(
src
=
xfered
,
dest
=
dest
,
original_basename
=
os
.
path
.
basename
(
source
),
follow
=
True
,
),
)
result
=
self
.
_execute_module
(
module_name
=
'copy'
,
module_args
=
new_module_args
,
task_vars
=
task_vars
)
else
:
result
=
dict
(
changed
=
True
)
# run the copy module
if
result
.
[
'changed'
]
and
self
.
_play_context
.
diff
:
new_module_args
=
self
.
_task
.
args
.
copy
()
result
[
'diff'
]
=
dict
(
before
=
dest_contents
,
after
=
resultant
,
before_header
=
dest
,
after_header
=
source
)
new_module_args
.
update
(
dict
(
src
=
xfered
,
dest
=
dest
,
original_basename
=
os
.
path
.
basename
(
source
),
follow
=
True
,
),
)
result
=
self
.
_execute_module
(
module_name
=
'copy'
,
module_args
=
new_module_args
,
task_vars
=
task_vars
)
if
result
.
get
(
'changed'
,
False
):
result
[
'diff'
]
=
dict
(
before
=
dest_contents
,
after
=
resultant
)
return
result
return
result
else
:
else
:
...
@@ -177,5 +181,8 @@ class ActionModule(ActionBase):
...
@@ -177,5 +181,8 @@ class ActionModule(ActionBase):
),
),
)
)
if
self
.
_play_context
.
check_mode
:
new_module_args
[
'CHECKMODE'
]
=
True
return
self
.
_execute_module
(
module_name
=
'file'
,
module_args
=
new_module_args
,
task_vars
=
task_vars
)
return
self
.
_execute_module
(
module_name
=
'file'
,
module_args
=
new_module_args
,
task_vars
=
task_vars
)
lib/ansible/plugins/callback/__init__.py
View file @
0b6fadaa
...
@@ -40,9 +40,9 @@ class CallbackBase:
...
@@ -40,9 +40,9 @@ class CallbackBase:
def
__init__
(
self
,
display
):
def
__init__
(
self
,
display
):
self
.
_display
=
display
self
.
_display
=
display
if
self
.
_display
.
verbosity
>=
4
:
if
self
.
_display
.
verbosity
>=
4
:
name
=
getattr
(
self
,
'CALLBACK_NAME'
,
'
with no defined name
'
)
name
=
getattr
(
self
,
'CALLBACK_NAME'
,
'
unnamed
'
)
ctype
=
getattr
(
self
,
'CALLBACK_TYPE'
,
'
unknwon
'
)
ctype
=
getattr
(
self
,
'CALLBACK_TYPE'
,
'
old
'
)
version
=
getattr
(
self
,
'CALLBACK_VERSION'
,
'
unknwon
'
)
version
=
getattr
(
self
,
'CALLBACK_VERSION'
,
'
1.0
'
)
self
.
_display
.
vvvv
(
'Loaded callback
%
s of type
%
s, v
%
s'
%
(
name
,
ctype
,
version
))
self
.
_display
.
vvvv
(
'Loaded callback
%
s of type
%
s, v
%
s'
%
(
name
,
ctype
,
version
))
def
_dump_results
(
self
,
result
,
indent
=
4
,
sort_keys
=
True
):
def
_dump_results
(
self
,
result
,
indent
=
4
,
sort_keys
=
True
):
...
@@ -117,6 +117,9 @@ class CallbackBase:
...
@@ -117,6 +117,9 @@ class CallbackBase:
def
playbook_on_stats
(
self
,
stats
):
def
playbook_on_stats
(
self
,
stats
):
pass
pass
def
on_file_diff
(
self
,
host
,
diff
):
self
.
_display
.
display
(
self
.
_dump_results
(
diff
))
####### V2 METHODS, by default they call v1 counterparts if possible ######
####### V2 METHODS, by default they call v1 counterparts if possible ######
def
v2_on_any
(
self
,
*
args
,
**
kwargs
):
def
v2_on_any
(
self
,
*
args
,
**
kwargs
):
self
.
on_any
(
args
,
kwargs
)
self
.
on_any
(
args
,
kwargs
)
...
@@ -204,3 +207,7 @@ class CallbackBase:
...
@@ -204,3 +207,7 @@ class CallbackBase:
def
v2_playbook_on_stats
(
self
,
stats
):
def
v2_playbook_on_stats
(
self
,
stats
):
self
.
playbook_on_stats
(
stats
)
self
.
playbook_on_stats
(
stats
)
def
v2_on_file_diff
(
self
,
result
):
host
=
result
.
_host
.
get_name
()
if
'diff'
in
result
.
_result
:
self
.
on_file_diff
(
host
,
result
.
_result
[
'diff'
])
lib/ansible/plugins/strategies/__init__.py
View file @
0b6fadaa
...
@@ -71,6 +71,7 @@ class StrategyBase:
...
@@ -71,6 +71,7 @@ class StrategyBase:
self
.
_loader
=
tqm
.
get_loader
()
self
.
_loader
=
tqm
.
get_loader
()
self
.
_final_q
=
tqm
.
_final_q
self
.
_final_q
=
tqm
.
_final_q
self
.
_step
=
getattr
(
tqm
.
_options
,
'step'
,
False
)
self
.
_step
=
getattr
(
tqm
.
_options
,
'step'
,
False
)
self
.
_diff
=
getattr
(
tqm
.
_options
,
'diff'
,
False
)
self
.
_display
=
display
self
.
_display
=
display
# internal counters
# internal counters
...
@@ -191,6 +192,9 @@ class StrategyBase:
...
@@ -191,6 +192,9 @@ class StrategyBase:
self
.
_tqm
.
_stats
.
increment
(
'changed'
,
host
.
name
)
self
.
_tqm
.
_stats
.
increment
(
'changed'
,
host
.
name
)
self
.
_tqm
.
send_callback
(
'v2_runner_on_ok'
,
task_result
)
self
.
_tqm
.
send_callback
(
'v2_runner_on_ok'
,
task_result
)
if
self
.
_diff
and
'diff'
in
task_result
.
_result
:
self
.
_tqm
.
send_callback
(
'v2_on_file_diff'
,
task_result
)
self
.
_pending_results
-=
1
self
.
_pending_results
-=
1
if
host
.
name
in
self
.
_blocked_hosts
:
if
host
.
name
in
self
.
_blocked_hosts
:
del
self
.
_blocked_hosts
[
host
.
name
]
del
self
.
_blocked_hosts
[
host
.
name
]
...
@@ -215,7 +219,7 @@ class StrategyBase:
...
@@ -215,7 +219,7 @@ class StrategyBase:
elif
result
[
0
]
==
'add_host'
:
elif
result
[
0
]
==
'add_host'
:
task_result
=
result
[
1
]
task_result
=
result
[
1
]
new_host_info
=
task_result
.
get
(
'add_host'
,
dict
())
new_host_info
=
task_result
.
get
(
'add_host'
,
dict
())
self
.
_add_host
(
new_host_info
)
self
.
_add_host
(
new_host_info
)
elif
result
[
0
]
==
'add_group'
:
elif
result
[
0
]
==
'add_group'
:
...
@@ -479,8 +483,7 @@ class StrategyBase:
...
@@ -479,8 +483,7 @@ class StrategyBase:
for
host
in
included_file
.
_hosts
:
for
host
in
included_file
.
_hosts
:
iterator
.
mark_host_failed
(
host
)
iterator
.
mark_host_failed
(
host
)
self
.
_tqm
.
_failed_hosts
[
host
.
name
]
=
True
self
.
_tqm
.
_failed_hosts
[
host
.
name
]
=
True
# FIXME: callback here?
self
.
_display
.
warning
(
str
(
e
))
print
(
e
)
continue
continue
self
.
_display
.
debug
(
"done running handlers, result is:
%
s"
%
result
)
self
.
_display
.
debug
(
"done running handlers, result is:
%
s"
%
result
)
return
result
return
result
...
...
lib/ansible/utils/display.py
View file @
0b6fadaa
...
@@ -34,6 +34,11 @@ from ansible.errors import AnsibleError
...
@@ -34,6 +34,11 @@ from ansible.errors import AnsibleError
from
ansible.utils.color
import
stringc
from
ansible.utils.color
import
stringc
from
ansible.utils.unicode
import
to_bytes
from
ansible.utils.unicode
import
to_bytes
# These are module level as we currently fork and serialize the whole process and locks in the objects don't play well with that
debug_lock
=
Lock
()
#TODO: make this a logging callback instead
#TODO: make this a logging callback instead
if
C
.
DEFAULT_LOG_PATH
:
if
C
.
DEFAULT_LOG_PATH
:
path
=
C
.
DEFAULT_LOG_PATH
path
=
C
.
DEFAULT_LOG_PATH
...
@@ -47,7 +52,6 @@ if C.DEFAULT_LOG_PATH:
...
@@ -47,7 +52,6 @@ if C.DEFAULT_LOG_PATH:
else
:
else
:
logger
=
None
logger
=
None
debug_lock
=
Lock
()
class
Display
:
class
Display
:
...
...
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