mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
E501 fixes (#22879)
This commit is contained in:
@@ -482,7 +482,8 @@ class ActionBase(with_metaclass(ABCMeta, object)):
|
||||
get_checksum=checksum,
|
||||
checksum_algo='sha1',
|
||||
)
|
||||
mystat = self._execute_module(module_name='stat', module_args=module_args, task_vars=all_vars, tmp=tmp, delete_remote_tmp=(tmp is None), wrap_async=False)
|
||||
mystat = self._execute_module(module_name='stat', module_args=module_args, task_vars=all_vars, tmp=tmp, delete_remote_tmp=(tmp is None),
|
||||
wrap_async=False)
|
||||
|
||||
if mystat.get('failed'):
|
||||
msg = mystat.get('module_stderr')
|
||||
@@ -674,7 +675,8 @@ class ActionBase(with_metaclass(ABCMeta, object)):
|
||||
|
||||
if wrap_async:
|
||||
# configure, upload, and chmod the async_wrapper module
|
||||
(async_module_style, shebang, async_module_data, async_module_path) = self._configure_module(module_name='async_wrapper', module_args=dict(), task_vars=task_vars)
|
||||
(async_module_style, shebang, async_module_data, async_module_path) = self._configure_module(module_name='async_wrapper', module_args=dict(),
|
||||
task_vars=task_vars)
|
||||
async_module_remote_filename = self._connection._shell.get_remote_filename(async_module_path)
|
||||
remote_async_module_path = self._connection._shell.join_path(tmp, async_module_remote_filename)
|
||||
self._transfer_data(remote_async_module_path, async_module_data)
|
||||
|
||||
@@ -41,7 +41,8 @@ class ActionModule(ActionBase):
|
||||
|
||||
if not isidentifier(k):
|
||||
result['failed'] = True
|
||||
result['msg'] = "The variable name '%s' is not valid. Variables must start with a letter or underscore character, and contain only letters, numbers and underscores." % k
|
||||
result['msg'] = ("The variable name '%s' is not valid. Variables must start with a letter or underscore character, and contain only "
|
||||
"letters, numbers and underscores." % k)
|
||||
return result
|
||||
|
||||
if isinstance(v, string_types) and v.lower() in ('true', 'false', 'yes', 'no'):
|
||||
|
||||
@@ -62,7 +62,8 @@ class ActionModule(ActionBase):
|
||||
|
||||
if not isidentifier(k):
|
||||
result['failed'] = True
|
||||
result['msg'] = "The variable name '%s' is not valid. Variables must start with a letter or underscore character, and contain only letters, numbers and underscores." % k
|
||||
result['msg'] = ("The variable name '%s' is not valid. Variables must start with a letter or underscore character, and contain only "
|
||||
"letters, numbers and underscores." % k)
|
||||
return result
|
||||
|
||||
stats['data'][k] = self._templar.template(v)
|
||||
|
||||
@@ -191,7 +191,8 @@ class ActionModule(ActionBase):
|
||||
# else only works with delegate_to
|
||||
if delegate_to is None and self._connection.transport not in ('ssh', 'paramiko', 'local', 'docker'):
|
||||
result['failed'] = True
|
||||
result['msg'] = "synchronize uses rsync to function. rsync needs to connect to the remote host via ssh, docker client or a direct filesystem copy. This remote host is being accessed via %s instead so it cannot work." % self._connection.transport
|
||||
result['msg'] = ("synchronize uses rsync to function. rsync needs to connect to the remote host via ssh, docker client or a direct filesystem "
|
||||
"copy. This remote host is being accessed via %s instead so it cannot work." % self._connection.transport)
|
||||
return result
|
||||
|
||||
use_ssh_args = _tmp_args.pop('use_ssh_args', None)
|
||||
@@ -382,5 +383,6 @@ class ActionModule(ActionBase):
|
||||
# Emit a warning about using python3 because synchronize is
|
||||
# somewhat unique in running on localhost
|
||||
result['exception'] = result['msg']
|
||||
result['msg'] = 'SyntaxError parsing module. Perhaps invoking "python" on your local (or delegate_to) machine invokes python3. You can set ansible_python_interpreter for localhost (or the delegate_to machine) to the location of python2 to fix this'
|
||||
result['msg'] = ('SyntaxError parsing module. Perhaps invoking "python" on your local (or delegate_to) machine invokes python3. '
|
||||
'You can set ansible_python_interpreter for localhost (or the delegate_to machine) to the location of python2 to fix this')
|
||||
return result
|
||||
|
||||
@@ -54,7 +54,9 @@ class CallbackModule(CallbackBase):
|
||||
|
||||
else:
|
||||
if delegated_vars:
|
||||
self._display.display("fatal: [%s -> %s]: FAILED! => %s" % (result._host.get_name(), delegated_vars['ansible_host'], self._dump_results(result._result)), color=C.COLOR_ERROR)
|
||||
self._display.display("fatal: [%s -> %s]: FAILED! => %s" % (result._host.get_name(), delegated_vars['ansible_host'],
|
||||
self._dump_results(result._result)),
|
||||
color=C.COLOR_ERROR)
|
||||
else:
|
||||
self._display.display("fatal: [%s]: FAILED! => %s" % (result._host.get_name(), self._dump_results(result._result)), color=C.COLOR_ERROR)
|
||||
|
||||
@@ -114,7 +116,9 @@ class CallbackModule(CallbackBase):
|
||||
|
||||
delegated_vars = result._result.get('_ansible_delegated_vars', None)
|
||||
if delegated_vars:
|
||||
self._display.display("fatal: [%s -> %s]: UNREACHABLE! => %s" % (result._host.get_name(), delegated_vars['ansible_host'], self._dump_results(result._result)), color=C.COLOR_UNREACHABLE)
|
||||
self._display.display("fatal: [%s -> %s]: UNREACHABLE! => %s" % (result._host.get_name(), delegated_vars['ansible_host'],
|
||||
self._dump_results(result._result)),
|
||||
color=C.COLOR_UNREACHABLE)
|
||||
else:
|
||||
self._display.display("fatal: [%s]: UNREACHABLE! => %s" % (result._host.get_name(), self._dump_results(result._result)), color=C.COLOR_UNREACHABLE)
|
||||
|
||||
|
||||
@@ -254,7 +254,8 @@ class CallbackModule(CallbackBase):
|
||||
self.token = os.getenv('LOGENTRIES_ANSIBLE_TOKEN')
|
||||
if self.token is None:
|
||||
self.disabled = True
|
||||
self._display.warning('Logentries token could not be loaded. The logentries token can be provided using the `LOGENTRIES_TOKEN` environment variable')
|
||||
self._display.warning('Logentries token could not be loaded. The logentries token can be provided using the `LOGENTRIES_TOKEN` environment '
|
||||
'variable')
|
||||
|
||||
self.flatten = os.getenv('LOGENTRIES_FLATTEN')
|
||||
if self.flatten is None:
|
||||
|
||||
@@ -56,13 +56,15 @@ class CallbackModule(CallbackBase):
|
||||
else:
|
||||
self._display.display(msg, color=C.COLOR_ERROR)
|
||||
|
||||
self._display.display("%s | FAILED! => %s" % (result._host.get_name(), self._dump_results(result._result, indent=0).replace('\n','')), color=C.COLOR_ERROR)
|
||||
self._display.display("%s | FAILED! => %s" % (result._host.get_name(), self._dump_results(result._result, indent=0).replace('\n','')),
|
||||
color=C.COLOR_ERROR)
|
||||
|
||||
def v2_runner_on_ok(self, result):
|
||||
if result._task.action in C.MODULE_NO_JSON:
|
||||
self._display.display(self._command_generic_msg(result._host.get_name(), result._result,'SUCCESS'), color=C.COLOR_OK)
|
||||
else:
|
||||
self._display.display("%s | SUCCESS => %s" % (result._host.get_name(), self._dump_results(result._result, indent=0).replace('\n','')), color=C.COLOR_OK)
|
||||
self._display.display("%s | SUCCESS => %s" % (result._host.get_name(), self._dump_results(result._result, indent=0).replace('\n','')),
|
||||
color=C.COLOR_OK)
|
||||
|
||||
|
||||
def v2_runner_on_unreachable(self, result):
|
||||
|
||||
@@ -69,7 +69,8 @@ class Connection(ConnectionBase):
|
||||
tries = 3
|
||||
self.conn = socket.socket()
|
||||
self.conn.settimeout(C.ACCELERATE_CONNECT_TIMEOUT)
|
||||
display.vvvv("attempting connection to %s via the accelerated port %d" % (self._play_context.remote_addr, self._play_context.accelerate_port), host=self._play_context.remote_addr)
|
||||
display.vvvv("attempting connection to %s via the accelerated port %d" % (self._play_context.remote_addr, self._play_context.accelerate_port),
|
||||
host=self._play_context.remote_addr)
|
||||
while tries > 0:
|
||||
try:
|
||||
self.conn.connect((self._play_context.remote_addr,self._play_context.accelerate_port))
|
||||
@@ -80,7 +81,8 @@ class Connection(ConnectionBase):
|
||||
tries -= 1
|
||||
if tries == 0:
|
||||
display.vvv("Could not connect via the accelerated connection, exceeded # of tries", host=self._play_context.remote_addr)
|
||||
raise AnsibleConnectionFailure("Failed to connect to %s on the accelerated port %s" % (self._play_context.remote_addr, self._play_context.accelerate_port))
|
||||
raise AnsibleConnectionFailure("Failed to connect to %s on the accelerated port %s" % (self._play_context.remote_addr,
|
||||
self._play_context.accelerate_port))
|
||||
elif wrong_user:
|
||||
display.vvv("Restarting daemon with a different remote_user", host=self._play_context.remote_addr)
|
||||
raise AnsibleError("The accelerated daemon was started on the remote with a different user")
|
||||
|
||||
@@ -204,7 +204,8 @@ class Connection(ConnectionBase):
|
||||
raise AnsibleError("paramiko is not installed")
|
||||
|
||||
port = self._play_context.port or 22
|
||||
display.vvv("ESTABLISH CONNECTION FOR USER: %s on PORT %s TO %s" % (self._play_context.remote_user, port, self._play_context.remote_addr), host=self._play_context.remote_addr)
|
||||
display.vvv("ESTABLISH CONNECTION FOR USER: %s on PORT %s TO %s" % (self._play_context.remote_user, port, self._play_context.remote_addr),
|
||||
host=self._play_context.remote_addr)
|
||||
|
||||
ssh = paramiko.SSHClient()
|
||||
|
||||
|
||||
@@ -657,11 +657,13 @@ class Connection(ConnectionBase):
|
||||
|
||||
if C.HOST_KEY_CHECKING:
|
||||
if cmd[0] == b"sshpass" and p.returncode == 6:
|
||||
raise AnsibleError('Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this. Please add this host\'s fingerprint to your known_hosts file to manage this host.')
|
||||
raise AnsibleError('Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support '
|
||||
'this. Please add this host\'s fingerprint to your known_hosts file to manage this host.')
|
||||
|
||||
controlpersisterror = b'Bad configuration option: ControlPersist' in b_stderr or b'unknown configuration option: ControlPersist' in b_stderr
|
||||
if p.returncode != 0 and controlpersisterror:
|
||||
raise AnsibleError('using -c ssh on certain older ssh versions may not support ControlPersist, set ANSIBLE_SSH_ARGS="" (or ssh_args in [ssh_connection] section of the config file) before running again')
|
||||
raise AnsibleError('using -c ssh on certain older ssh versions may not support ControlPersist, set ANSIBLE_SSH_ARGS="" '
|
||||
'(or ssh_args in [ssh_connection] section of the config file) before running again')
|
||||
|
||||
if p.returncode == 255 and in_data and checkrc:
|
||||
raise AnsibleConnectionFailure('SSH Error: data could not be sent to remote host "%s". Make sure this host can be reached over ssh' % self.host)
|
||||
|
||||
@@ -260,7 +260,8 @@ class Connection(ConnectionBase):
|
||||
stdin_push_failed = False
|
||||
command_id = self.protocol.run_command(self.shell_id, to_bytes(command), map(to_bytes, args), console_mode_stdin=(stdin_iterator is None))
|
||||
|
||||
# TODO: try/except around this, so we can get/return the command result on a broken pipe or other failure (probably more useful than the 500 that comes from this)
|
||||
# TODO: try/except around this, so we can get/return the command result on a broken pipe or other failure (probably more useful than the 500 that
|
||||
# comes from this)
|
||||
try:
|
||||
if stdin_iterator:
|
||||
for (data, is_last) in stdin_iterator:
|
||||
|
||||
@@ -188,5 +188,6 @@ class LookupModule(LookupBase):
|
||||
if skip:
|
||||
return []
|
||||
else:
|
||||
raise AnsibleLookupError("No file was found when using with_first_found. Use the 'skip: true' option to allow this task to be skipped if no files are found")
|
||||
raise AnsibleLookupError("No file was found when using with_first_found. Use the 'skip: true' option to allow this task to be skipped if no "
|
||||
"files are found")
|
||||
|
||||
|
||||
@@ -84,10 +84,10 @@ class ShellModule(ShModule):
|
||||
# used by a variety of shells on the remote host to invoke a python
|
||||
# "one-liner".
|
||||
shell_escaped_path = shlex_quote(path)
|
||||
test = "set rc flag; [ -r %(p)s ] %(shell_or)s set rc 2; [ -f %(p)s ] %(shell_or)s set rc 1; [ -d %(p)s ] %(shell_and)s set rc 3; %(i)s -V 2>/dev/null %(shell_or)s set rc 4; [ x\"$rc\" != \"xflag\" ] %(shell_and)s echo \"$rc \"%(p)s %(shell_and)s exit 0" % dict(p=shell_escaped_path, i=python_interp, shell_and=self._SHELL_AND, shell_or=self._SHELL_OR)
|
||||
test = "set rc flag; [ -r %(p)s ] %(shell_or)s set rc 2; [ -f %(p)s ] %(shell_or)s set rc 1; [ -d %(p)s ] %(shell_and)s set rc 3; %(i)s -V 2>/dev/null %(shell_or)s set rc 4; [ x\"$rc\" != \"xflag\" ] %(shell_and)s echo \"$rc \"%(p)s %(shell_and)s exit 0" % dict(p=shell_escaped_path, i=python_interp, shell_and=self._SHELL_AND, shell_or=self._SHELL_OR) # NOQA
|
||||
csums = [
|
||||
u"({0} -c 'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();{2}afile = open(\"'{1}'\", \"rb\"){2}buf = afile.read(BLOCKSIZE){2}while len(buf) > 0:{2}\thasher.update(buf){2}\tbuf = afile.read(BLOCKSIZE){2}afile.close(){2}print(hasher.hexdigest())' 2>/dev/null)".format(python_interp, shell_escaped_path, self._SHELL_EMBEDDED_PY_EOL), # Python > 2.4 (including python3)
|
||||
u"({0} -c 'import sha; BLOCKSIZE = 65536; hasher = sha.sha();{2}afile = open(\"'{1}'\", \"rb\"){2}buf = afile.read(BLOCKSIZE){2}while len(buf) > 0:{2}\thasher.update(buf){2}\tbuf = afile.read(BLOCKSIZE){2}afile.close(){2}print(hasher.hexdigest())' 2>/dev/null)".format(python_interp, shell_escaped_path, self._SHELL_EMBEDDED_PY_EOL), # Python == 2.4
|
||||
u"({0} -c 'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();{2}afile = open(\"'{1}'\", \"rb\"){2}buf = afile.read(BLOCKSIZE){2}while len(buf) > 0:{2}\thasher.update(buf){2}\tbuf = afile.read(BLOCKSIZE){2}afile.close(){2}print(hasher.hexdigest())' 2>/dev/null)".format(python_interp, shell_escaped_path, self._SHELL_EMBEDDED_PY_EOL), # NOQA Python > 2.4 (including python3)
|
||||
u"({0} -c 'import sha; BLOCKSIZE = 65536; hasher = sha.sha();{2}afile = open(\"'{1}'\", \"rb\"){2}buf = afile.read(BLOCKSIZE){2}while len(buf) > 0:{2}\thasher.update(buf){2}\tbuf = afile.read(BLOCKSIZE){2}afile.close(){2}print(hasher.hexdigest())' 2>/dev/null)".format(python_interp, shell_escaped_path, self._SHELL_EMBEDDED_PY_EOL), # NOQA Python == 2.4
|
||||
]
|
||||
|
||||
cmd = (" %s " % self._SHELL_OR).join(csums)
|
||||
|
||||
@@ -72,10 +72,10 @@ class ShellModule(ShellBase):
|
||||
# used by a variety of shells on the remote host to invoke a python
|
||||
# "one-liner".
|
||||
shell_escaped_path = shlex_quote(path)
|
||||
test = "rc=flag; [ -r %(p)s ] %(shell_or)s rc=2; [ -f %(p)s ] %(shell_or)s rc=1; [ -d %(p)s ] %(shell_and)s rc=3; %(i)s -V 2>/dev/null %(shell_or)s rc=4; [ x\"$rc\" != \"xflag\" ] %(shell_and)s echo \"${rc} \"%(p)s %(shell_and)s exit 0" % dict(p=shell_escaped_path, i=python_interp, shell_and=self._SHELL_AND, shell_or=self._SHELL_OR)
|
||||
test = "rc=flag; [ -r %(p)s ] %(shell_or)s rc=2; [ -f %(p)s ] %(shell_or)s rc=1; [ -d %(p)s ] %(shell_and)s rc=3; %(i)s -V 2>/dev/null %(shell_or)s rc=4; [ x\"$rc\" != \"xflag\" ] %(shell_and)s echo \"${rc} \"%(p)s %(shell_and)s exit 0" % dict(p=shell_escaped_path, i=python_interp, shell_and=self._SHELL_AND, shell_or=self._SHELL_OR) # NOQA
|
||||
csums = [
|
||||
u"({0} -c 'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();{2}afile = open(\"'{1}'\", \"rb\"){2}buf = afile.read(BLOCKSIZE){2}while len(buf) > 0:{2}\thasher.update(buf){2}\tbuf = afile.read(BLOCKSIZE){2}afile.close(){2}print(hasher.hexdigest())' 2>/dev/null)".format(python_interp, shell_escaped_path, self._SHELL_EMBEDDED_PY_EOL), # Python > 2.4 (including python3)
|
||||
u"({0} -c 'import sha; BLOCKSIZE = 65536; hasher = sha.sha();{2}afile = open(\"'{1}'\", \"rb\"){2}buf = afile.read(BLOCKSIZE){2}while len(buf) > 0:{2}\thasher.update(buf){2}\tbuf = afile.read(BLOCKSIZE){2}afile.close(){2}print(hasher.hexdigest())' 2>/dev/null)".format(python_interp, shell_escaped_path, self._SHELL_EMBEDDED_PY_EOL), # Python == 2.4
|
||||
u"({0} -c 'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();{2}afile = open(\"'{1}'\", \"rb\"){2}buf = afile.read(BLOCKSIZE){2}while len(buf) > 0:{2}\thasher.update(buf){2}\tbuf = afile.read(BLOCKSIZE){2}afile.close(){2}print(hasher.hexdigest())' 2>/dev/null)".format(python_interp, shell_escaped_path, self._SHELL_EMBEDDED_PY_EOL), # NOQA Python > 2.4 (including python3)
|
||||
u"({0} -c 'import sha; BLOCKSIZE = 65536; hasher = sha.sha();{2}afile = open(\"'{1}'\", \"rb\"){2}buf = afile.read(BLOCKSIZE){2}while len(buf) > 0:{2}\thasher.update(buf){2}\tbuf = afile.read(BLOCKSIZE){2}afile.close(){2}print(hasher.hexdigest())' 2>/dev/null)".format(python_interp, shell_escaped_path, self._SHELL_EMBEDDED_PY_EOL), # NOQA Python == 2.4
|
||||
]
|
||||
|
||||
cmd = (" %s " % self._SHELL_OR).join(csums)
|
||||
|
||||
@@ -468,7 +468,8 @@ class StrategyBase:
|
||||
|
||||
# and if none were found, then we raise an error
|
||||
if not found:
|
||||
msg = "The requested handler '%s' was not found in either the main handlers list nor in the listening handlers list" % handler_name
|
||||
msg = ("The requested handler '%s' was not found in either the main handlers list nor in the listening "
|
||||
"handlers list" % handler_name)
|
||||
if C.ERROR_ON_MISSING_HANDLER:
|
||||
raise AnsibleError(msg)
|
||||
else:
|
||||
@@ -693,8 +694,9 @@ class StrategyBase:
|
||||
tags = tags.split(',')
|
||||
if len(tags) > 0:
|
||||
if len(included_file._task.tags) > 0:
|
||||
raise AnsibleParserError("Include tasks should not specify tags in more than one way (both via args and directly on the task). Mixing tag specify styles is prohibited for whole import hierarchy, not only for single import statement",
|
||||
obj=included_file._task._ds)
|
||||
raise AnsibleParserError("Include tasks should not specify tags in more than one way (both via args and directly on the task). "
|
||||
"Mixing tag specify styles is prohibited for whole import hierarchy, not only for single import statement",
|
||||
obj=included_file._task._ds)
|
||||
display.deprecated("You should not specify tags in the include parameters. All tags should be specified using the task-level option")
|
||||
included_file._task.tags = tags
|
||||
|
||||
|
||||
@@ -96,7 +96,10 @@ class StrategyModule(StrategyBase):
|
||||
num_rescue += 1
|
||||
elif s.run_state == PlayIterator.ITERATING_ALWAYS:
|
||||
num_always += 1
|
||||
display.debug("done counting tasks in each state of execution:\n\tnum_setups: %s\n\tnum_tasks: %s\n\tnum_rescue: %s\n\tnum_always: %s" % (num_setups, num_tasks, num_rescue, num_always))
|
||||
display.debug("done counting tasks in each state of execution:\n\tnum_setups: %s\n\tnum_tasks: %s\n\tnum_rescue: %s\n\tnum_always: %s" % (num_setups,
|
||||
num_tasks,
|
||||
num_rescue,
|
||||
num_always))
|
||||
|
||||
def _advance_selected_hosts(hosts, cur_block, cur_state):
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user