We couldn't copy to_unicode, to_bytes, to_str into module_utils because
of licensing. So once created it we had two sets of functions that did
the same things but had different implementations. To remedy that, this
change removes the ansible.utils.unicode versions of those functions.
display.display(u'\n'+"To properly namespace this role, remove each of the above and re-import %s/%s from scratch"%(github_user,github_repo),color=C.COLOR_CHANGED)
display.display(u'\nTo properly namespace this role, remove each of the above and re-import %s/%s from scratch'%(github_user,github_repo),
# give lookup task 'context' for subdir (mostly needed for first_found)
forsubdirin['template','var','file']:#TODO: move this to constants?
forsubdirin['template','var','file']:#TODO: move this to constants?
ifsubdirinself._task.action:
break
setattr(mylookup,'_subdir',subdir+'s')
@ -245,7 +246,9 @@ class TaskExecutor:
loop_pause=self._task.loop_control.pauseor0
ifloop_varintask_vars:
display.warning("The loop variable '%s' is already in use. You should set the `loop_var` value in the `loop_control` option for the task to something else to avoid variable collisions and unexpected behavior."%loop_var)
display.warning(u"The loop variable '%s' is already in use."
u"You should set the `loop_var` value in the `loop_control` option for the task"
u" to something else to avoid variable collisions and unexpected behavior."%loop_var)
# sys.executable is not set in some cornercases. #13585
display.warning('Unable to determine python interpreter from sys.executable. Using /usr/bin/python default. You can correct this by setting ansible_python_interpreter for localhost')
display.warning('Unable to determine python interpreter from sys.executable. Using /usr/bin/python default.'
' You can correct this by setting ansible_python_interpreter for localhost')
# make sure script output is unicode so that json loader will output
# unicode strings itself
try:
self.data=to_unicode(stdout,errors="strict")
self.data=to_text(stdout,errors="strict")
exceptExceptionase:
raiseAnsibleError("inventory data from {0} contained characters that cannot be interpreted as UTF-8: {1}".format(to_str(self.filename),to_str(e)))
raiseAnsibleError("inventory data from {0} contained characters that cannot be interpreted as UTF-8: {1}".format(to_native(self.filename),to_native(e)))
# see comment about _meta below
self.host_vars_from_top=None
@ -78,11 +78,11 @@ class InventoryScript:
self.raw=self._loader.load(self.data)
exceptExceptionase:
sys.stderr.write(err+"\n")
raiseAnsibleError("failed to parse executable inventory script results from {0}: {1}".format(to_str(self.filename),to_str(e)))
raiseAnsibleError("failed to parse executable inventory script results from {0}: {1}".format(to_native(self.filename),to_native(e)))
ifnotisinstance(self.raw,Mapping):
sys.stderr.write(err+"\n")
raiseAnsibleError("failed to parse executable inventory script results from {0}: data needs to be formatted as a json dict".format(to_str(self.filename)))
raiseAnsibleError("failed to parse executable inventory script results from {0}: data needs to be formatted as a json dict".format(to_native(self.filename)))
group=None
for(group_name,data)inself.raw.items():
@ -152,7 +152,7 @@ class InventoryScript:
try:
got=self.host_vars_from_top.get(host.name,{})
exceptAttributeErrorase:
raiseAnsibleError("Improperly formated host information for %s: %s"%(host.name,to_str(e)))
raiseAnsibleError("Improperly formated host information for %s: %s"%(host.name,to_native(e)))
raiseAnsibleError("Problem running vault password script %s (%s). If this is not a script, remove the executable bit from the file."%(''.join(this_path),e))
CRYPTO_UPGRADE="ansible-vault requires a newer version of pycrypto than the one installed on your platform. You may fix this with OS-specific commands such as: yum install python-devel; rpm -e --nodeps python-crypto; pip install pycrypto"
CRYPTO_UPGRADE="ansible-vault requires a newer version of pycrypto than the one installed on your platform." \
" You may fix this with OS-specific commands such as: yum install python-devel; rpm -e --nodeps python-crypto; pip install pycrypto"
b_HEADER=b'$ANSIBLE_VAULT'
HEADER='$ANSIBLE_VAULT'
@ -105,6 +107,7 @@ def check_prereqs():
classAnsibleVaultError(AnsibleError):
pass
defis_encrypted(b_data):
""" Test if this is vault encrypted data blob
@ -116,6 +119,7 @@ def is_encrypted(b_data):
returnTrue
returnFalse
defis_encrypted_file(file_obj):
"""Test if the contents of a file obj are a vault encrypted data blob.
display.warning(u'While constructing a mapping from {1}, line {2}, column {3}, found a duplicate dict key ({0}). Using last defined value only.'.format(key,*mapping.ansible_pos))
display.warning(u'While constructing a mapping from {1}, line {2}, column {3}, found a duplicate dict key ({0}).'
u' Using last defined value only.'.format(key,*mapping.ansible_pos))
raiseAnsibleError('Failed to change ownership of the temporary files Ansible needs to create despite connecting as root. Unprivileged become user would be unable to read the file.')
raiseAnsibleError('Failed to change ownership of the temporary files Ansible needs to create despite connecting as root.'
' Unprivileged become user would be unable to read the file.')
elifres['rc']!=0:
ifC.ALLOW_WORLD_READABLE_TMPFILES:
# chown and fs acls failed -- do things this insecure
# way only if the user opted in in the config file
display.warning('Using world-readable permissions for temporary files Ansible needs to create when becoming an unprivileged user which may be insecure. For information on securing this, see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user')
display.warning('Using world-readable permissions for temporary files Ansible needs to create when becoming an unprivileged user.'
' This may be insecure. For information on securing this, see'
raiseAnsibleError('Failed to set file mode on remote files (rc: {0}, err: {1})'.format(res['rc'],res['stderr']))
else:
raiseAnsibleError('Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: {0}, err: {1}). For information on working around this, see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user'.format(res['rc'],res['stderr']))
raiseAnsibleError('Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user'
' (rc: {0}, err: {1}). For information on working around this,'
' see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user'.format(res['rc'],res['stderr']))
elifexecute:
# Can't depend on the file being transferred with execute
# permissions. Only need user perms because no become was
@ -438,7 +445,7 @@ class ActionBase(with_metaclass(ABCMeta, object)):
mystat['stat']['checksum']='1'
# happens sometimes when it is a dir and not on bsd
ifnot'checksum'inmystat['stat']:
if'checksum'notinmystat['stat']:
mystat['stat']['checksum']=''
returnmystat['stat']
@ -461,15 +468,14 @@ class ActionBase(with_metaclass(ABCMeta, object)):
else:
x=remote_stat['checksum']# if 1, file is missing
exceptAnsibleErrorase:
errormsg=to_unicode(e)
iferrormsg.endswith('Permission denied'):
errormsg=to_text(e)
iferrormsg.endswith(u'Permission denied'):
x="2"# cannot read file
eliferrormsg.endswith('MODULE FAILURE'):
eliferrormsg.endswith(u'MODULE FAILURE'):
x="4"# python not found or module uncaught exception
finally:
returnx
def_remote_expand_user(self,path):
''' takes a remote path and performs tilde expansion on the remote host '''
ifnotpath.startswith('~'):# FIXME: Windows paths may start with "~ instead of just ~
@ -681,7 +687,8 @@ class ActionBase(with_metaclass(ABCMeta, object)):