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),
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
# 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
# make sure script output is unicode so that json loader will output
# unicode strings itself
# unicode strings itself
try:
try:
self.data=to_unicode(stdout,errors="strict")
self.data=to_text(stdout,errors="strict")
exceptExceptionase:
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
# see comment about _meta below
self.host_vars_from_top=None
self.host_vars_from_top=None
@ -78,11 +78,11 @@ class InventoryScript:
self.raw=self._loader.load(self.data)
self.raw=self._loader.load(self.data)
exceptExceptionase:
exceptExceptionase:
sys.stderr.write(err+"\n")
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):
ifnotisinstance(self.raw,Mapping):
sys.stderr.write(err+"\n")
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
group=None
for(group_name,data)inself.raw.items():
for(group_name,data)inself.raw.items():
@ -152,7 +152,7 @@ class InventoryScript:
try:
try:
got=self.host_vars_from_top.get(host.name,{})
got=self.host_vars_from_top.get(host.name,{})
exceptAttributeErrorase:
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'
b_HEADER=b'$ANSIBLE_VAULT'
HEADER='$ANSIBLE_VAULT'
HEADER='$ANSIBLE_VAULT'
@ -105,6 +107,7 @@ def check_prereqs():
classAnsibleVaultError(AnsibleError):
classAnsibleVaultError(AnsibleError):
pass
pass
defis_encrypted(b_data):
defis_encrypted(b_data):
""" Test if this is vault encrypted data blob
""" Test if this is vault encrypted data blob
@ -116,6 +119,7 @@ def is_encrypted(b_data):
returnTrue
returnTrue
returnFalse
returnFalse
defis_encrypted_file(file_obj):
defis_encrypted_file(file_obj):
"""Test if the contents of a file obj are a vault encrypted data blob.
"""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:
elifres['rc']!=0:
ifC.ALLOW_WORLD_READABLE_TMPFILES:
ifC.ALLOW_WORLD_READABLE_TMPFILES:
# chown and fs acls failed -- do things this insecure
# chown and fs acls failed -- do things this insecure
# way only if the user opted in in the config file
# 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']))
raiseAnsibleError('Failed to set file mode on remote files (rc: {0}, err: {1})'.format(res['rc'],res['stderr']))
else:
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:
elifexecute:
# Can't depend on the file being transferred with execute
# Can't depend on the file being transferred with execute
# permissions. Only need user perms because no become was
# permissions. Only need user perms because no become was
@ -438,7 +445,7 @@ class ActionBase(with_metaclass(ABCMeta, object)):
mystat['stat']['checksum']='1'
mystat['stat']['checksum']='1'
# happens sometimes when it is a dir and not on bsd
# happens sometimes when it is a dir and not on bsd
ifnot'checksum'inmystat['stat']:
if'checksum'notinmystat['stat']:
mystat['stat']['checksum']=''
mystat['stat']['checksum']=''
returnmystat['stat']
returnmystat['stat']
@ -453,26 +460,25 @@ class ActionBase(with_metaclass(ABCMeta, object)):