status
stringclasses
1 value
repo_name
stringclasses
31 values
repo_url
stringclasses
31 values
issue_id
int64
1
104k
title
stringlengths
4
233
body
stringlengths
0
186k
issue_url
stringlengths
38
56
pull_url
stringlengths
37
54
before_fix_sha
stringlengths
40
40
after_fix_sha
stringlengths
40
40
report_datetime
timestamp[us, tz=UTC]
language
stringclasses
5 values
commit_datetime
timestamp[us, tz=UTC]
updated_file
stringlengths
7
188
chunk_content
stringlengths
1
1.03M
closed
ansible/ansible
https://github.com/ansible/ansible
73,659
no_log module argument processing can change 'changed' task field
##### SUMMARY no_log module argument processing can change 'changed' task field, which is probably an undesirable side-effect ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME unsure, ansible core processing task responses ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible 2.10.6 ansible 2.7.7 ``` ##### CONFIGURATION <!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes --> ```paste below ``` ##### OS / ENVIRONMENT <!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. --> Debian Linux 10 Buster ##### STEPS TO REPRODUCE <!--- Describe exactly how to reproduce the problem, using a minimal test-case --> use simple playbook using single htpasswd module <!--- Paste example playbooks or commands between quotes below --> ```yaml - hosts: localhost tasks: - htpasswd: path: /tmp/xx username: a password: a ``` <!--- HINT: You can paste gist.github.com links for larger files --> ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> * subsequent calls to `ansible-playbook playbook.yml` yields to task changed=False OR * general notice in ansible documentation of such behavior ##### ACTUAL RESULTS <!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) --> * every call of the playbook results in task changed=True * the module 'changed' return value itself it correct according to runtime debugging * the error depends on the actual value of the `no_log` module argument * probably, there's an undocumented side-effect in general no_log processing, where it the edge case (value 'a') is found in several places of the module response and replaced as requested. the issue is that replacing takes place even in task.changed field which should not be touched (imho) <!--- Paste verbatim command output between quotes --> ```paste below TASK [htpasswd] ************************************************************************************************************************************************************************************************** task path: /a.yml:4 ... <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1613725466.4347775-207888894675995/AnsiballZ_htpasswd.py && sleep 0' ... changed: [localhost] => { "changed": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", <<<<<<<<<<<<<<<<<<<<<<<< "invocation": { "module_args": { "attributes": null, "backup": null, "content": null, "create": true, "crypt_scheme": "********pr_md5_crypt", "delimiter": null, "directory_mode": null, "follow": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "force": null, "group": null, "mode": null, "name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "owner": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "path": "/tmp/xx", "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "present", "unsafe_writes": null, "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" } }, "msg": "******** ********lre********dy present" } ``` module trace ```paste below > /root/.ansible/tmp/ansible-tmp-1613724872.5574055-221454552474871/debug_dir/__main__.py(266)main() -> module.exit_json(msg=msg, changed=changed) (Pdb) l 261 else: 262 module.fail_json(msg="Invalid state: %s" % state) 263 264 check_file_attrs(module, changed, msg) 265 breakpoint() 266 -> module.exit_json(msg=msg, changed=changed) 267 except Exception as e: 268 module.fail_json(msg=to_native(e)) 269 270 271 if __name__ == '__main__': (Pdb) module <ansible.module_utils.basic.AnsibleModule object at 0x7f50d5a34c50> (Pdb) changed False <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (Pdb) msg 'a already present' (Pdb) s ```
https://github.com/ansible/ansible/issues/73659
https://github.com/ansible/ansible/pull/82217
f42984eeb36b092678690e39cd74179f96c8d438
6e448edc63ecfdaf3f6ebb2e015e2d3c12dd1d95
2021-02-19T09:57:15Z
python
2023-11-16T19:04:34Z
lib/ansible/module_utils/basic.py
if not self._clean: to_clean_args = args if PY2: if isinstance(args, text_type): to_clean_args = to_bytes(args) else: if isinstance(args, binary_type): to_clean_args = to_text(args) if isinstance(args, (text_type, binary_type)): to_clean_args = shlex.split(to_clean_args) clean_args = [] is_passwd = False for arg in (to_native(a) for a in to_clean_args): if is_passwd: is_passwd = False clean_args.append('********') continue if PASSWD_ARG_RE.match(arg): sep_idx = arg.find('=') if sep_idx > -1: clean_args.append('%s=********' % arg[:sep_idx]) continue else: is_passwd = True arg = heuristic_log_sanitize(arg, self.no_log_values) clean_args.append(arg) self._clean = ' '.join(shlex_quote(arg) for arg in clean_args)
closed
ansible/ansible
https://github.com/ansible/ansible
73,659
no_log module argument processing can change 'changed' task field
##### SUMMARY no_log module argument processing can change 'changed' task field, which is probably an undesirable side-effect ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME unsure, ansible core processing task responses ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible 2.10.6 ansible 2.7.7 ``` ##### CONFIGURATION <!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes --> ```paste below ``` ##### OS / ENVIRONMENT <!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. --> Debian Linux 10 Buster ##### STEPS TO REPRODUCE <!--- Describe exactly how to reproduce the problem, using a minimal test-case --> use simple playbook using single htpasswd module <!--- Paste example playbooks or commands between quotes below --> ```yaml - hosts: localhost tasks: - htpasswd: path: /tmp/xx username: a password: a ``` <!--- HINT: You can paste gist.github.com links for larger files --> ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> * subsequent calls to `ansible-playbook playbook.yml` yields to task changed=False OR * general notice in ansible documentation of such behavior ##### ACTUAL RESULTS <!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) --> * every call of the playbook results in task changed=True * the module 'changed' return value itself it correct according to runtime debugging * the error depends on the actual value of the `no_log` module argument * probably, there's an undocumented side-effect in general no_log processing, where it the edge case (value 'a') is found in several places of the module response and replaced as requested. the issue is that replacing takes place even in task.changed field which should not be touched (imho) <!--- Paste verbatim command output between quotes --> ```paste below TASK [htpasswd] ************************************************************************************************************************************************************************************************** task path: /a.yml:4 ... <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1613725466.4347775-207888894675995/AnsiballZ_htpasswd.py && sleep 0' ... changed: [localhost] => { "changed": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", <<<<<<<<<<<<<<<<<<<<<<<< "invocation": { "module_args": { "attributes": null, "backup": null, "content": null, "create": true, "crypt_scheme": "********pr_md5_crypt", "delimiter": null, "directory_mode": null, "follow": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "force": null, "group": null, "mode": null, "name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "owner": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "path": "/tmp/xx", "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "present", "unsafe_writes": null, "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" } }, "msg": "******** ********lre********dy present" } ``` module trace ```paste below > /root/.ansible/tmp/ansible-tmp-1613724872.5574055-221454552474871/debug_dir/__main__.py(266)main() -> module.exit_json(msg=msg, changed=changed) (Pdb) l 261 else: 262 module.fail_json(msg="Invalid state: %s" % state) 263 264 check_file_attrs(module, changed, msg) 265 breakpoint() 266 -> module.exit_json(msg=msg, changed=changed) 267 except Exception as e: 268 module.fail_json(msg=to_native(e)) 269 270 271 if __name__ == '__main__': (Pdb) module <ansible.module_utils.basic.AnsibleModule object at 0x7f50d5a34c50> (Pdb) changed False <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (Pdb) msg 'a already present' (Pdb) s ```
https://github.com/ansible/ansible/issues/73659
https://github.com/ansible/ansible/pull/82217
f42984eeb36b092678690e39cd74179f96c8d438
6e448edc63ecfdaf3f6ebb2e015e2d3c12dd1d95
2021-02-19T09:57:15Z
python
2023-11-16T19:04:34Z
lib/ansible/module_utils/basic.py
return self._clean def _restore_signal_handlers(self): if PY2 and sys.platform != 'win32': signal.signal(signal.SIGPIPE, signal.SIG_DFL) def run_command(self, args, check_rc=False, close_fds=True, executable=None, data=None, binary_data=False, path_prefix=None, cwd=None, use_unsafe_shell=False, prompt_regex=None, environ_update=None, umask=None, encoding='utf-8', errors='surrogate_or_strict', expand_user_and_vars=True, pass_fds=None, before_communicate_callback=None, ignore_invalid_cwd=True, handle_exceptions=True): ''' Execute a command, returns rc, stdout, and stderr. The mechanism of this method for reading stdout and stderr differs from that of CPython subprocess.Popen.communicate, in that this method will stop reading once the spawned command has exited and stdout and stderr have been consumed, as opposed to waiting until stdout/stderr are closed. This can be an important distinction, when taken into account that a forked or backgrounded process may hold stdout or stderr open for longer than the spawned command. :arg args: is the command to run * If args is a list, the command will be run with shell=False. * If args is a string and use_unsafe_shell=False it will split args to a list and run with shell=False * If args is a string and use_unsafe_shell=True it runs with shell=True. :kw check_rc: Whether to call fail_json in case of non zero RC. Default False :kw close_fds: See documentation for subprocess.Popen(). Default True :kw executable: See documentation for subprocess.Popen(). Default None :kw data: If given, information to write to the stdin of the command :kw binary_data: If False, append a newline to the data. Default False :kw path_prefix: If given, additional path to find the command in. This adds to the PATH environment variable so helper commands in the same directory can also be found
closed
ansible/ansible
https://github.com/ansible/ansible
73,659
no_log module argument processing can change 'changed' task field
##### SUMMARY no_log module argument processing can change 'changed' task field, which is probably an undesirable side-effect ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME unsure, ansible core processing task responses ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible 2.10.6 ansible 2.7.7 ``` ##### CONFIGURATION <!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes --> ```paste below ``` ##### OS / ENVIRONMENT <!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. --> Debian Linux 10 Buster ##### STEPS TO REPRODUCE <!--- Describe exactly how to reproduce the problem, using a minimal test-case --> use simple playbook using single htpasswd module <!--- Paste example playbooks or commands between quotes below --> ```yaml - hosts: localhost tasks: - htpasswd: path: /tmp/xx username: a password: a ``` <!--- HINT: You can paste gist.github.com links for larger files --> ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> * subsequent calls to `ansible-playbook playbook.yml` yields to task changed=False OR * general notice in ansible documentation of such behavior ##### ACTUAL RESULTS <!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) --> * every call of the playbook results in task changed=True * the module 'changed' return value itself it correct according to runtime debugging * the error depends on the actual value of the `no_log` module argument * probably, there's an undocumented side-effect in general no_log processing, where it the edge case (value 'a') is found in several places of the module response and replaced as requested. the issue is that replacing takes place even in task.changed field which should not be touched (imho) <!--- Paste verbatim command output between quotes --> ```paste below TASK [htpasswd] ************************************************************************************************************************************************************************************************** task path: /a.yml:4 ... <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1613725466.4347775-207888894675995/AnsiballZ_htpasswd.py && sleep 0' ... changed: [localhost] => { "changed": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", <<<<<<<<<<<<<<<<<<<<<<<< "invocation": { "module_args": { "attributes": null, "backup": null, "content": null, "create": true, "crypt_scheme": "********pr_md5_crypt", "delimiter": null, "directory_mode": null, "follow": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "force": null, "group": null, "mode": null, "name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "owner": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "path": "/tmp/xx", "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "present", "unsafe_writes": null, "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" } }, "msg": "******** ********lre********dy present" } ``` module trace ```paste below > /root/.ansible/tmp/ansible-tmp-1613724872.5574055-221454552474871/debug_dir/__main__.py(266)main() -> module.exit_json(msg=msg, changed=changed) (Pdb) l 261 else: 262 module.fail_json(msg="Invalid state: %s" % state) 263 264 check_file_attrs(module, changed, msg) 265 breakpoint() 266 -> module.exit_json(msg=msg, changed=changed) 267 except Exception as e: 268 module.fail_json(msg=to_native(e)) 269 270 271 if __name__ == '__main__': (Pdb) module <ansible.module_utils.basic.AnsibleModule object at 0x7f50d5a34c50> (Pdb) changed False <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (Pdb) msg 'a already present' (Pdb) s ```
https://github.com/ansible/ansible/issues/73659
https://github.com/ansible/ansible/pull/82217
f42984eeb36b092678690e39cd74179f96c8d438
6e448edc63ecfdaf3f6ebb2e015e2d3c12dd1d95
2021-02-19T09:57:15Z
python
2023-11-16T19:04:34Z
lib/ansible/module_utils/basic.py
:kw cwd: If given, working directory to run the command inside :kw use_unsafe_shell: See `args` parameter. Default False :kw prompt_regex: Regex string (not a compiled regex) which can be used to detect prompts in the stdout which would otherwise cause the execution to hang (especially if no input data is specified) :kw environ_update: dictionary to *update* environ variables with :kw umask: Umask to be used when running the command. Default None :kw encoding: Since we return native strings, on python3 we need to know the encoding to use to transform from bytes to text. If you want to always get bytes back, use encoding=None. The default is "utf-8". This does not affect transformation of strings given as args. :kw errors: Since we return native strings, on python3 we need to transform stdout and stderr from bytes to text. If the bytes are undecodable in the ``encoding`` specified, then use this error handler to deal with them. The default is ``surrogate_or_strict`` which means that the bytes will be decoded using the surrogateescape error handler if available (available on all python3 versions we support) otherwise a UnicodeError traceback will be raised. This does not affect transformations of strings given as args. :kw expand_user_and_vars: When ``use_unsafe_shell=False`` this argument dictates whether ``~`` is expanded in paths and environment variables are expanded before running the command. When ``True`` a string such as ``$SHELL`` will be expanded regardless of escaping. When ``False`` and ``use_unsafe_shell=False`` no path or variable expansion will be done. :kw pass_fds: When running on Python 3 this argument dictates which file descriptors should be passed to an underlying ``Popen`` constructor. On Python 2, this will set ``close_fds`` to False.
closed
ansible/ansible
https://github.com/ansible/ansible
73,659
no_log module argument processing can change 'changed' task field
##### SUMMARY no_log module argument processing can change 'changed' task field, which is probably an undesirable side-effect ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME unsure, ansible core processing task responses ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible 2.10.6 ansible 2.7.7 ``` ##### CONFIGURATION <!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes --> ```paste below ``` ##### OS / ENVIRONMENT <!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. --> Debian Linux 10 Buster ##### STEPS TO REPRODUCE <!--- Describe exactly how to reproduce the problem, using a minimal test-case --> use simple playbook using single htpasswd module <!--- Paste example playbooks or commands between quotes below --> ```yaml - hosts: localhost tasks: - htpasswd: path: /tmp/xx username: a password: a ``` <!--- HINT: You can paste gist.github.com links for larger files --> ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> * subsequent calls to `ansible-playbook playbook.yml` yields to task changed=False OR * general notice in ansible documentation of such behavior ##### ACTUAL RESULTS <!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) --> * every call of the playbook results in task changed=True * the module 'changed' return value itself it correct according to runtime debugging * the error depends on the actual value of the `no_log` module argument * probably, there's an undocumented side-effect in general no_log processing, where it the edge case (value 'a') is found in several places of the module response and replaced as requested. the issue is that replacing takes place even in task.changed field which should not be touched (imho) <!--- Paste verbatim command output between quotes --> ```paste below TASK [htpasswd] ************************************************************************************************************************************************************************************************** task path: /a.yml:4 ... <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1613725466.4347775-207888894675995/AnsiballZ_htpasswd.py && sleep 0' ... changed: [localhost] => { "changed": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", <<<<<<<<<<<<<<<<<<<<<<<< "invocation": { "module_args": { "attributes": null, "backup": null, "content": null, "create": true, "crypt_scheme": "********pr_md5_crypt", "delimiter": null, "directory_mode": null, "follow": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "force": null, "group": null, "mode": null, "name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "owner": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "path": "/tmp/xx", "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "present", "unsafe_writes": null, "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" } }, "msg": "******** ********lre********dy present" } ``` module trace ```paste below > /root/.ansible/tmp/ansible-tmp-1613724872.5574055-221454552474871/debug_dir/__main__.py(266)main() -> module.exit_json(msg=msg, changed=changed) (Pdb) l 261 else: 262 module.fail_json(msg="Invalid state: %s" % state) 263 264 check_file_attrs(module, changed, msg) 265 breakpoint() 266 -> module.exit_json(msg=msg, changed=changed) 267 except Exception as e: 268 module.fail_json(msg=to_native(e)) 269 270 271 if __name__ == '__main__': (Pdb) module <ansible.module_utils.basic.AnsibleModule object at 0x7f50d5a34c50> (Pdb) changed False <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (Pdb) msg 'a already present' (Pdb) s ```
https://github.com/ansible/ansible/issues/73659
https://github.com/ansible/ansible/pull/82217
f42984eeb36b092678690e39cd74179f96c8d438
6e448edc63ecfdaf3f6ebb2e015e2d3c12dd1d95
2021-02-19T09:57:15Z
python
2023-11-16T19:04:34Z
lib/ansible/module_utils/basic.py
:kw before_communicate_callback: This function will be called after ``Popen`` object will be created but before communicating to the process. (``Popen`` object will be passed to callback as a first argument) :kw ignore_invalid_cwd: This flag indicates whether an invalid ``cwd`` (non-existent or not a directory) should be ignored or should raise an exception. :kw handle_exceptions: This flag indicates whether an exception will be handled inline and issue a failed_json or if the caller should handle it. :returns: A 3-tuple of return code (integer), stdout (native string), and stderr (native string). On python2, stdout and stderr are both byte strings. On python3, stdout and stderr are text strings converted according to the encoding and errors parameters. If you want byte strings on python3, use encoding=None to turn decoding to text off. ''' self._clean = None if not isinstance(args, (list, binary_type, text_type)): msg = "Argument 'args' to run_command must be list or string" self.fail_json(rc=257, cmd=args, msg=msg) shell = False if use_unsafe_shell: if isinstance(args, list): args = b" ".join([to_bytes(shlex_quote(x), errors='surrogate_or_strict') for x in args]) else: args = to_bytes(args, errors='surrogate_or_strict') if executable:
closed
ansible/ansible
https://github.com/ansible/ansible
73,659
no_log module argument processing can change 'changed' task field
##### SUMMARY no_log module argument processing can change 'changed' task field, which is probably an undesirable side-effect ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME unsure, ansible core processing task responses ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible 2.10.6 ansible 2.7.7 ``` ##### CONFIGURATION <!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes --> ```paste below ``` ##### OS / ENVIRONMENT <!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. --> Debian Linux 10 Buster ##### STEPS TO REPRODUCE <!--- Describe exactly how to reproduce the problem, using a minimal test-case --> use simple playbook using single htpasswd module <!--- Paste example playbooks or commands between quotes below --> ```yaml - hosts: localhost tasks: - htpasswd: path: /tmp/xx username: a password: a ``` <!--- HINT: You can paste gist.github.com links for larger files --> ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> * subsequent calls to `ansible-playbook playbook.yml` yields to task changed=False OR * general notice in ansible documentation of such behavior ##### ACTUAL RESULTS <!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) --> * every call of the playbook results in task changed=True * the module 'changed' return value itself it correct according to runtime debugging * the error depends on the actual value of the `no_log` module argument * probably, there's an undocumented side-effect in general no_log processing, where it the edge case (value 'a') is found in several places of the module response and replaced as requested. the issue is that replacing takes place even in task.changed field which should not be touched (imho) <!--- Paste verbatim command output between quotes --> ```paste below TASK [htpasswd] ************************************************************************************************************************************************************************************************** task path: /a.yml:4 ... <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1613725466.4347775-207888894675995/AnsiballZ_htpasswd.py && sleep 0' ... changed: [localhost] => { "changed": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", <<<<<<<<<<<<<<<<<<<<<<<< "invocation": { "module_args": { "attributes": null, "backup": null, "content": null, "create": true, "crypt_scheme": "********pr_md5_crypt", "delimiter": null, "directory_mode": null, "follow": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "force": null, "group": null, "mode": null, "name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "owner": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "path": "/tmp/xx", "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "present", "unsafe_writes": null, "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" } }, "msg": "******** ********lre********dy present" } ``` module trace ```paste below > /root/.ansible/tmp/ansible-tmp-1613724872.5574055-221454552474871/debug_dir/__main__.py(266)main() -> module.exit_json(msg=msg, changed=changed) (Pdb) l 261 else: 262 module.fail_json(msg="Invalid state: %s" % state) 263 264 check_file_attrs(module, changed, msg) 265 breakpoint() 266 -> module.exit_json(msg=msg, changed=changed) 267 except Exception as e: 268 module.fail_json(msg=to_native(e)) 269 270 271 if __name__ == '__main__': (Pdb) module <ansible.module_utils.basic.AnsibleModule object at 0x7f50d5a34c50> (Pdb) changed False <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (Pdb) msg 'a already present' (Pdb) s ```
https://github.com/ansible/ansible/issues/73659
https://github.com/ansible/ansible/pull/82217
f42984eeb36b092678690e39cd74179f96c8d438
6e448edc63ecfdaf3f6ebb2e015e2d3c12dd1d95
2021-02-19T09:57:15Z
python
2023-11-16T19:04:34Z
lib/ansible/module_utils/basic.py
executable = to_bytes(executable, errors='surrogate_or_strict') args = [executable, b'-c', args] elif self._shell not in (None, '/bin/sh'): args = [to_bytes(self._shell, errors='surrogate_or_strict'), b'-c', args] else: shell = True else: if isinstance(args, (binary_type, text_type)): if PY2: args = to_bytes(args, errors='surrogate_or_strict') elif PY3: args = to_text(args, errors='surrogateescape') args = shlex.split(args) if expand_user_and_vars: args = [to_bytes(os.path.expanduser(os.path.expandvars(x)), errors='surrogate_or_strict') for x in args if x is not None] else: args = [to_bytes(x, errors='surrogate_or_strict') for x in args if x is not None] prompt_re = None if prompt_regex: if isinstance(prompt_regex, text_type): if PY3: prompt_regex = to_bytes(prompt_regex, errors='surrogateescape') elif PY2: prompt_regex = to_bytes(prompt_regex, errors='surrogate_or_strict') try: prompt_re = re.compile(prompt_regex, re.MULTILINE)
closed
ansible/ansible
https://github.com/ansible/ansible
73,659
no_log module argument processing can change 'changed' task field
##### SUMMARY no_log module argument processing can change 'changed' task field, which is probably an undesirable side-effect ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME unsure, ansible core processing task responses ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible 2.10.6 ansible 2.7.7 ``` ##### CONFIGURATION <!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes --> ```paste below ``` ##### OS / ENVIRONMENT <!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. --> Debian Linux 10 Buster ##### STEPS TO REPRODUCE <!--- Describe exactly how to reproduce the problem, using a minimal test-case --> use simple playbook using single htpasswd module <!--- Paste example playbooks or commands between quotes below --> ```yaml - hosts: localhost tasks: - htpasswd: path: /tmp/xx username: a password: a ``` <!--- HINT: You can paste gist.github.com links for larger files --> ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> * subsequent calls to `ansible-playbook playbook.yml` yields to task changed=False OR * general notice in ansible documentation of such behavior ##### ACTUAL RESULTS <!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) --> * every call of the playbook results in task changed=True * the module 'changed' return value itself it correct according to runtime debugging * the error depends on the actual value of the `no_log` module argument * probably, there's an undocumented side-effect in general no_log processing, where it the edge case (value 'a') is found in several places of the module response and replaced as requested. the issue is that replacing takes place even in task.changed field which should not be touched (imho) <!--- Paste verbatim command output between quotes --> ```paste below TASK [htpasswd] ************************************************************************************************************************************************************************************************** task path: /a.yml:4 ... <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1613725466.4347775-207888894675995/AnsiballZ_htpasswd.py && sleep 0' ... changed: [localhost] => { "changed": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", <<<<<<<<<<<<<<<<<<<<<<<< "invocation": { "module_args": { "attributes": null, "backup": null, "content": null, "create": true, "crypt_scheme": "********pr_md5_crypt", "delimiter": null, "directory_mode": null, "follow": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "force": null, "group": null, "mode": null, "name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "owner": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "path": "/tmp/xx", "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "present", "unsafe_writes": null, "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" } }, "msg": "******** ********lre********dy present" } ``` module trace ```paste below > /root/.ansible/tmp/ansible-tmp-1613724872.5574055-221454552474871/debug_dir/__main__.py(266)main() -> module.exit_json(msg=msg, changed=changed) (Pdb) l 261 else: 262 module.fail_json(msg="Invalid state: %s" % state) 263 264 check_file_attrs(module, changed, msg) 265 breakpoint() 266 -> module.exit_json(msg=msg, changed=changed) 267 except Exception as e: 268 module.fail_json(msg=to_native(e)) 269 270 271 if __name__ == '__main__': (Pdb) module <ansible.module_utils.basic.AnsibleModule object at 0x7f50d5a34c50> (Pdb) changed False <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (Pdb) msg 'a already present' (Pdb) s ```
https://github.com/ansible/ansible/issues/73659
https://github.com/ansible/ansible/pull/82217
f42984eeb36b092678690e39cd74179f96c8d438
6e448edc63ecfdaf3f6ebb2e015e2d3c12dd1d95
2021-02-19T09:57:15Z
python
2023-11-16T19:04:34Z
lib/ansible/module_utils/basic.py
except re.error: self.fail_json(msg="invalid prompt regular expression given to run_command") rc = 0 msg = None st_in = None env = os.environ.copy() env.update(self.run_command_environ_update or {}) env.update(environ_update or {}) if path_prefix: path = env.get('PATH', '') if path: env['PATH'] = "%s:%s" % (path_prefix, path) else: env['PATH'] = path_prefix if 'PYTHONPATH' in env: pypaths = [x for x in env['PYTHONPATH'].split(':') if x and not x.endswith('/ansible_modlib.zip') and not x.endswith('/debug_dir')] if pypaths and any(pypaths): env['PYTHONPATH'] = ':'.join(pypaths) if data: st_in = subprocess.PIPE def preexec():
closed
ansible/ansible
https://github.com/ansible/ansible
73,659
no_log module argument processing can change 'changed' task field
##### SUMMARY no_log module argument processing can change 'changed' task field, which is probably an undesirable side-effect ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME unsure, ansible core processing task responses ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible 2.10.6 ansible 2.7.7 ``` ##### CONFIGURATION <!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes --> ```paste below ``` ##### OS / ENVIRONMENT <!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. --> Debian Linux 10 Buster ##### STEPS TO REPRODUCE <!--- Describe exactly how to reproduce the problem, using a minimal test-case --> use simple playbook using single htpasswd module <!--- Paste example playbooks or commands between quotes below --> ```yaml - hosts: localhost tasks: - htpasswd: path: /tmp/xx username: a password: a ``` <!--- HINT: You can paste gist.github.com links for larger files --> ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> * subsequent calls to `ansible-playbook playbook.yml` yields to task changed=False OR * general notice in ansible documentation of such behavior ##### ACTUAL RESULTS <!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) --> * every call of the playbook results in task changed=True * the module 'changed' return value itself it correct according to runtime debugging * the error depends on the actual value of the `no_log` module argument * probably, there's an undocumented side-effect in general no_log processing, where it the edge case (value 'a') is found in several places of the module response and replaced as requested. the issue is that replacing takes place even in task.changed field which should not be touched (imho) <!--- Paste verbatim command output between quotes --> ```paste below TASK [htpasswd] ************************************************************************************************************************************************************************************************** task path: /a.yml:4 ... <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1613725466.4347775-207888894675995/AnsiballZ_htpasswd.py && sleep 0' ... changed: [localhost] => { "changed": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", <<<<<<<<<<<<<<<<<<<<<<<< "invocation": { "module_args": { "attributes": null, "backup": null, "content": null, "create": true, "crypt_scheme": "********pr_md5_crypt", "delimiter": null, "directory_mode": null, "follow": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "force": null, "group": null, "mode": null, "name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "owner": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "path": "/tmp/xx", "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "present", "unsafe_writes": null, "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" } }, "msg": "******** ********lre********dy present" } ``` module trace ```paste below > /root/.ansible/tmp/ansible-tmp-1613724872.5574055-221454552474871/debug_dir/__main__.py(266)main() -> module.exit_json(msg=msg, changed=changed) (Pdb) l 261 else: 262 module.fail_json(msg="Invalid state: %s" % state) 263 264 check_file_attrs(module, changed, msg) 265 breakpoint() 266 -> module.exit_json(msg=msg, changed=changed) 267 except Exception as e: 268 module.fail_json(msg=to_native(e)) 269 270 271 if __name__ == '__main__': (Pdb) module <ansible.module_utils.basic.AnsibleModule object at 0x7f50d5a34c50> (Pdb) changed False <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (Pdb) msg 'a already present' (Pdb) s ```
https://github.com/ansible/ansible/issues/73659
https://github.com/ansible/ansible/pull/82217
f42984eeb36b092678690e39cd74179f96c8d438
6e448edc63ecfdaf3f6ebb2e015e2d3c12dd1d95
2021-02-19T09:57:15Z
python
2023-11-16T19:04:34Z
lib/ansible/module_utils/basic.py
self._restore_signal_handlers() if umask: os.umask(umask) kwargs = dict( executable=executable, shell=shell, close_fds=close_fds, stdin=st_in, stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=preexec, env=env, ) if PY3 and pass_fds: kwargs["pass_fds"] = pass_fds elif PY2 and pass_fds: kwargs['close_fds'] = False if cwd: cwd = to_bytes(os.path.abspath(os.path.expanduser(cwd)), errors='surrogate_or_strict') if os.path.isdir(cwd):
closed
ansible/ansible
https://github.com/ansible/ansible
73,659
no_log module argument processing can change 'changed' task field
##### SUMMARY no_log module argument processing can change 'changed' task field, which is probably an undesirable side-effect ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME unsure, ansible core processing task responses ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible 2.10.6 ansible 2.7.7 ``` ##### CONFIGURATION <!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes --> ```paste below ``` ##### OS / ENVIRONMENT <!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. --> Debian Linux 10 Buster ##### STEPS TO REPRODUCE <!--- Describe exactly how to reproduce the problem, using a minimal test-case --> use simple playbook using single htpasswd module <!--- Paste example playbooks or commands between quotes below --> ```yaml - hosts: localhost tasks: - htpasswd: path: /tmp/xx username: a password: a ``` <!--- HINT: You can paste gist.github.com links for larger files --> ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> * subsequent calls to `ansible-playbook playbook.yml` yields to task changed=False OR * general notice in ansible documentation of such behavior ##### ACTUAL RESULTS <!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) --> * every call of the playbook results in task changed=True * the module 'changed' return value itself it correct according to runtime debugging * the error depends on the actual value of the `no_log` module argument * probably, there's an undocumented side-effect in general no_log processing, where it the edge case (value 'a') is found in several places of the module response and replaced as requested. the issue is that replacing takes place even in task.changed field which should not be touched (imho) <!--- Paste verbatim command output between quotes --> ```paste below TASK [htpasswd] ************************************************************************************************************************************************************************************************** task path: /a.yml:4 ... <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1613725466.4347775-207888894675995/AnsiballZ_htpasswd.py && sleep 0' ... changed: [localhost] => { "changed": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", <<<<<<<<<<<<<<<<<<<<<<<< "invocation": { "module_args": { "attributes": null, "backup": null, "content": null, "create": true, "crypt_scheme": "********pr_md5_crypt", "delimiter": null, "directory_mode": null, "follow": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "force": null, "group": null, "mode": null, "name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "owner": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "path": "/tmp/xx", "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "present", "unsafe_writes": null, "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" } }, "msg": "******** ********lre********dy present" } ``` module trace ```paste below > /root/.ansible/tmp/ansible-tmp-1613724872.5574055-221454552474871/debug_dir/__main__.py(266)main() -> module.exit_json(msg=msg, changed=changed) (Pdb) l 261 else: 262 module.fail_json(msg="Invalid state: %s" % state) 263 264 check_file_attrs(module, changed, msg) 265 breakpoint() 266 -> module.exit_json(msg=msg, changed=changed) 267 except Exception as e: 268 module.fail_json(msg=to_native(e)) 269 270 271 if __name__ == '__main__': (Pdb) module <ansible.module_utils.basic.AnsibleModule object at 0x7f50d5a34c50> (Pdb) changed False <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (Pdb) msg 'a already present' (Pdb) s ```
https://github.com/ansible/ansible/issues/73659
https://github.com/ansible/ansible/pull/82217
f42984eeb36b092678690e39cd74179f96c8d438
6e448edc63ecfdaf3f6ebb2e015e2d3c12dd1d95
2021-02-19T09:57:15Z
python
2023-11-16T19:04:34Z
lib/ansible/module_utils/basic.py
kwargs['cwd'] = cwd elif not ignore_invalid_cwd: self.fail_json(msg="Provided cwd is not a valid directory: %s" % cwd) try: if self._debug: self.log('Executing: ' + self._clean_args(args)) cmd = subprocess.Popen(args, **kwargs) if before_communicate_callback: before_communicate_callback(cmd) stdout = b'' stderr = b'' if hasattr(selectors, 'PollSelector'): selector = selectors.PollSelector() else: selector = selectors.SelectSelector() if data: if not binary_data: data += '\n' if isinstance(data, text_type): data = to_bytes(data) selector.register(cmd.stdout, selectors.EVENT_READ) selector.register(cmd.stderr, selectors.EVENT_READ) if os.name == 'posix': fcntl.fcntl(cmd.stdout.fileno(), fcntl.F_SETFL, fcntl.fcntl(cmd.stdout.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK) fcntl.fcntl(cmd.stderr.fileno(), fcntl.F_SETFL, fcntl.fcntl(cmd.stderr.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK) if data:
closed
ansible/ansible
https://github.com/ansible/ansible
73,659
no_log module argument processing can change 'changed' task field
##### SUMMARY no_log module argument processing can change 'changed' task field, which is probably an undesirable side-effect ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME unsure, ansible core processing task responses ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible 2.10.6 ansible 2.7.7 ``` ##### CONFIGURATION <!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes --> ```paste below ``` ##### OS / ENVIRONMENT <!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. --> Debian Linux 10 Buster ##### STEPS TO REPRODUCE <!--- Describe exactly how to reproduce the problem, using a minimal test-case --> use simple playbook using single htpasswd module <!--- Paste example playbooks or commands between quotes below --> ```yaml - hosts: localhost tasks: - htpasswd: path: /tmp/xx username: a password: a ``` <!--- HINT: You can paste gist.github.com links for larger files --> ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> * subsequent calls to `ansible-playbook playbook.yml` yields to task changed=False OR * general notice in ansible documentation of such behavior ##### ACTUAL RESULTS <!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) --> * every call of the playbook results in task changed=True * the module 'changed' return value itself it correct according to runtime debugging * the error depends on the actual value of the `no_log` module argument * probably, there's an undocumented side-effect in general no_log processing, where it the edge case (value 'a') is found in several places of the module response and replaced as requested. the issue is that replacing takes place even in task.changed field which should not be touched (imho) <!--- Paste verbatim command output between quotes --> ```paste below TASK [htpasswd] ************************************************************************************************************************************************************************************************** task path: /a.yml:4 ... <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1613725466.4347775-207888894675995/AnsiballZ_htpasswd.py && sleep 0' ... changed: [localhost] => { "changed": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", <<<<<<<<<<<<<<<<<<<<<<<< "invocation": { "module_args": { "attributes": null, "backup": null, "content": null, "create": true, "crypt_scheme": "********pr_md5_crypt", "delimiter": null, "directory_mode": null, "follow": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "force": null, "group": null, "mode": null, "name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "owner": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "path": "/tmp/xx", "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "present", "unsafe_writes": null, "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" } }, "msg": "******** ********lre********dy present" } ``` module trace ```paste below > /root/.ansible/tmp/ansible-tmp-1613724872.5574055-221454552474871/debug_dir/__main__.py(266)main() -> module.exit_json(msg=msg, changed=changed) (Pdb) l 261 else: 262 module.fail_json(msg="Invalid state: %s" % state) 263 264 check_file_attrs(module, changed, msg) 265 breakpoint() 266 -> module.exit_json(msg=msg, changed=changed) 267 except Exception as e: 268 module.fail_json(msg=to_native(e)) 269 270 271 if __name__ == '__main__': (Pdb) module <ansible.module_utils.basic.AnsibleModule object at 0x7f50d5a34c50> (Pdb) changed False <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (Pdb) msg 'a already present' (Pdb) s ```
https://github.com/ansible/ansible/issues/73659
https://github.com/ansible/ansible/pull/82217
f42984eeb36b092678690e39cd74179f96c8d438
6e448edc63ecfdaf3f6ebb2e015e2d3c12dd1d95
2021-02-19T09:57:15Z
python
2023-11-16T19:04:34Z
lib/ansible/module_utils/basic.py
cmd.stdin.write(data) cmd.stdin.close() while True: events = selector.select(1) stdout_changed = False for key, event in events: b_chunk = key.fileobj.read(32768) if not b_chunk: selector.unregister(key.fileobj) elif key.fileobj == cmd.stdout: stdout += b_chunk stdout_changed = True elif key.fileobj == cmd.stderr: stderr += b_chunk if prompt_re and stdout_changed and prompt_re.search(stdout) and not data: if encoding: stdout = to_native(stdout, encoding=encoding, errors=errors) return (257, stdout, "A prompt was encountered while running a command, but no input data was specified") if (not events or not selector.get_map()) and cmd.poll() is not None: break
closed
ansible/ansible
https://github.com/ansible/ansible
73,659
no_log module argument processing can change 'changed' task field
##### SUMMARY no_log module argument processing can change 'changed' task field, which is probably an undesirable side-effect ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME unsure, ansible core processing task responses ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible 2.10.6 ansible 2.7.7 ``` ##### CONFIGURATION <!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes --> ```paste below ``` ##### OS / ENVIRONMENT <!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. --> Debian Linux 10 Buster ##### STEPS TO REPRODUCE <!--- Describe exactly how to reproduce the problem, using a minimal test-case --> use simple playbook using single htpasswd module <!--- Paste example playbooks or commands between quotes below --> ```yaml - hosts: localhost tasks: - htpasswd: path: /tmp/xx username: a password: a ``` <!--- HINT: You can paste gist.github.com links for larger files --> ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> * subsequent calls to `ansible-playbook playbook.yml` yields to task changed=False OR * general notice in ansible documentation of such behavior ##### ACTUAL RESULTS <!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) --> * every call of the playbook results in task changed=True * the module 'changed' return value itself it correct according to runtime debugging * the error depends on the actual value of the `no_log` module argument * probably, there's an undocumented side-effect in general no_log processing, where it the edge case (value 'a') is found in several places of the module response and replaced as requested. the issue is that replacing takes place even in task.changed field which should not be touched (imho) <!--- Paste verbatim command output between quotes --> ```paste below TASK [htpasswd] ************************************************************************************************************************************************************************************************** task path: /a.yml:4 ... <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1613725466.4347775-207888894675995/AnsiballZ_htpasswd.py && sleep 0' ... changed: [localhost] => { "changed": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", <<<<<<<<<<<<<<<<<<<<<<<< "invocation": { "module_args": { "attributes": null, "backup": null, "content": null, "create": true, "crypt_scheme": "********pr_md5_crypt", "delimiter": null, "directory_mode": null, "follow": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "force": null, "group": null, "mode": null, "name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "owner": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "path": "/tmp/xx", "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "present", "unsafe_writes": null, "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" } }, "msg": "******** ********lre********dy present" } ``` module trace ```paste below > /root/.ansible/tmp/ansible-tmp-1613724872.5574055-221454552474871/debug_dir/__main__.py(266)main() -> module.exit_json(msg=msg, changed=changed) (Pdb) l 261 else: 262 module.fail_json(msg="Invalid state: %s" % state) 263 264 check_file_attrs(module, changed, msg) 265 breakpoint() 266 -> module.exit_json(msg=msg, changed=changed) 267 except Exception as e: 268 module.fail_json(msg=to_native(e)) 269 270 271 if __name__ == '__main__': (Pdb) module <ansible.module_utils.basic.AnsibleModule object at 0x7f50d5a34c50> (Pdb) changed False <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (Pdb) msg 'a already present' (Pdb) s ```
https://github.com/ansible/ansible/issues/73659
https://github.com/ansible/ansible/pull/82217
f42984eeb36b092678690e39cd74179f96c8d438
6e448edc63ecfdaf3f6ebb2e015e2d3c12dd1d95
2021-02-19T09:57:15Z
python
2023-11-16T19:04:34Z
lib/ansible/module_utils/basic.py
elif not selector.get_map() and cmd.poll() is None: cmd.wait() break cmd.stdout.close() cmd.stderr.close() selector.close() rc = cmd.returncode except (OSError, IOError) as e: self.log("Error Executing CMD:%s Exception:%s" % (self._clean_args(args), to_native(e))) if handle_exceptions: self.fail_json(rc=e.errno, stdout=b'', stderr=b'', msg=to_native(e), cmd=self._clean_args(args)) else: raise e except Exception as e: self.log("Error Executing CMD:%s Exception:%s" % (self._clean_args(args), to_native(traceback.format_exc()))) if handle_exceptions: self.fail_json(rc=257, stdout=b'', stderr=b'', msg=to_native(e), exception=traceback.format_exc(), cmd=self._clean_args(args)) else: raise e if rc != 0 and check_rc: msg = heuristic_log_sanitize(stderr.rstrip(), self.no_log_values) self.fail_json(cmd=self._clean_args(args), rc=rc, stdout=stdout, stderr=stderr, msg=msg) if encoding is not None: return (rc, to_native(stdout, encoding=encoding, errors=errors), to_native(stderr, encoding=encoding, errors=errors)) return (rc, stdout, stderr) def append_to_file(self, filename, str):
closed
ansible/ansible
https://github.com/ansible/ansible
73,659
no_log module argument processing can change 'changed' task field
##### SUMMARY no_log module argument processing can change 'changed' task field, which is probably an undesirable side-effect ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME unsure, ansible core processing task responses ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible 2.10.6 ansible 2.7.7 ``` ##### CONFIGURATION <!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes --> ```paste below ``` ##### OS / ENVIRONMENT <!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. --> Debian Linux 10 Buster ##### STEPS TO REPRODUCE <!--- Describe exactly how to reproduce the problem, using a minimal test-case --> use simple playbook using single htpasswd module <!--- Paste example playbooks or commands between quotes below --> ```yaml - hosts: localhost tasks: - htpasswd: path: /tmp/xx username: a password: a ``` <!--- HINT: You can paste gist.github.com links for larger files --> ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> * subsequent calls to `ansible-playbook playbook.yml` yields to task changed=False OR * general notice in ansible documentation of such behavior ##### ACTUAL RESULTS <!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) --> * every call of the playbook results in task changed=True * the module 'changed' return value itself it correct according to runtime debugging * the error depends on the actual value of the `no_log` module argument * probably, there's an undocumented side-effect in general no_log processing, where it the edge case (value 'a') is found in several places of the module response and replaced as requested. the issue is that replacing takes place even in task.changed field which should not be touched (imho) <!--- Paste verbatim command output between quotes --> ```paste below TASK [htpasswd] ************************************************************************************************************************************************************************************************** task path: /a.yml:4 ... <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1613725466.4347775-207888894675995/AnsiballZ_htpasswd.py && sleep 0' ... changed: [localhost] => { "changed": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", <<<<<<<<<<<<<<<<<<<<<<<< "invocation": { "module_args": { "attributes": null, "backup": null, "content": null, "create": true, "crypt_scheme": "********pr_md5_crypt", "delimiter": null, "directory_mode": null, "follow": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "force": null, "group": null, "mode": null, "name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "owner": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "path": "/tmp/xx", "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "present", "unsafe_writes": null, "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" } }, "msg": "******** ********lre********dy present" } ``` module trace ```paste below > /root/.ansible/tmp/ansible-tmp-1613724872.5574055-221454552474871/debug_dir/__main__.py(266)main() -> module.exit_json(msg=msg, changed=changed) (Pdb) l 261 else: 262 module.fail_json(msg="Invalid state: %s" % state) 263 264 check_file_attrs(module, changed, msg) 265 breakpoint() 266 -> module.exit_json(msg=msg, changed=changed) 267 except Exception as e: 268 module.fail_json(msg=to_native(e)) 269 270 271 if __name__ == '__main__': (Pdb) module <ansible.module_utils.basic.AnsibleModule object at 0x7f50d5a34c50> (Pdb) changed False <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (Pdb) msg 'a already present' (Pdb) s ```
https://github.com/ansible/ansible/issues/73659
https://github.com/ansible/ansible/pull/82217
f42984eeb36b092678690e39cd74179f96c8d438
6e448edc63ecfdaf3f6ebb2e015e2d3c12dd1d95
2021-02-19T09:57:15Z
python
2023-11-16T19:04:34Z
lib/ansible/module_utils/basic.py
filename = os.path.expandvars(os.path.expanduser(filename)) fh = open(filename, 'a') fh.write(str) fh.close() def bytes_to_human(self, size): return bytes_to_human(size) pretty_bytes = bytes_to_human def human_to_bytes(self, number, isbits=False): return human_to_bytes(number, isbits) # # is_executable = is_executable @staticmethod def get_buffer_size(fd): try: buffer_size = fcntl.fcntl(fd, 1032) except Exception: try: buffer_size = select.PIPE_BUF except Exception: buffer_size = 9000 return buffer_size def get_module_path():
closed
ansible/ansible
https://github.com/ansible/ansible
73,659
no_log module argument processing can change 'changed' task field
##### SUMMARY no_log module argument processing can change 'changed' task field, which is probably an undesirable side-effect ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME unsure, ansible core processing task responses ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible 2.10.6 ansible 2.7.7 ``` ##### CONFIGURATION <!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes --> ```paste below ``` ##### OS / ENVIRONMENT <!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. --> Debian Linux 10 Buster ##### STEPS TO REPRODUCE <!--- Describe exactly how to reproduce the problem, using a minimal test-case --> use simple playbook using single htpasswd module <!--- Paste example playbooks or commands between quotes below --> ```yaml - hosts: localhost tasks: - htpasswd: path: /tmp/xx username: a password: a ``` <!--- HINT: You can paste gist.github.com links for larger files --> ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> * subsequent calls to `ansible-playbook playbook.yml` yields to task changed=False OR * general notice in ansible documentation of such behavior ##### ACTUAL RESULTS <!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) --> * every call of the playbook results in task changed=True * the module 'changed' return value itself it correct according to runtime debugging * the error depends on the actual value of the `no_log` module argument * probably, there's an undocumented side-effect in general no_log processing, where it the edge case (value 'a') is found in several places of the module response and replaced as requested. the issue is that replacing takes place even in task.changed field which should not be touched (imho) <!--- Paste verbatim command output between quotes --> ```paste below TASK [htpasswd] ************************************************************************************************************************************************************************************************** task path: /a.yml:4 ... <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1613725466.4347775-207888894675995/AnsiballZ_htpasswd.py && sleep 0' ... changed: [localhost] => { "changed": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", <<<<<<<<<<<<<<<<<<<<<<<< "invocation": { "module_args": { "attributes": null, "backup": null, "content": null, "create": true, "crypt_scheme": "********pr_md5_crypt", "delimiter": null, "directory_mode": null, "follow": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "force": null, "group": null, "mode": null, "name": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "owner": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "path": "/tmp/xx", "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "present", "unsafe_writes": null, "username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" } }, "msg": "******** ********lre********dy present" } ``` module trace ```paste below > /root/.ansible/tmp/ansible-tmp-1613724872.5574055-221454552474871/debug_dir/__main__.py(266)main() -> module.exit_json(msg=msg, changed=changed) (Pdb) l 261 else: 262 module.fail_json(msg="Invalid state: %s" % state) 263 264 check_file_attrs(module, changed, msg) 265 breakpoint() 266 -> module.exit_json(msg=msg, changed=changed) 267 except Exception as e: 268 module.fail_json(msg=to_native(e)) 269 270 271 if __name__ == '__main__': (Pdb) module <ansible.module_utils.basic.AnsibleModule object at 0x7f50d5a34c50> (Pdb) changed False <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (Pdb) msg 'a already present' (Pdb) s ```
https://github.com/ansible/ansible/issues/73659
https://github.com/ansible/ansible/pull/82217
f42984eeb36b092678690e39cd74179f96c8d438
6e448edc63ecfdaf3f6ebb2e015e2d3c12dd1d95
2021-02-19T09:57:15Z
python
2023-11-16T19:04:34Z
lib/ansible/module_utils/basic.py
return os.path.dirname(os.path.realpath(__file__)) def __getattr__(importable_name): """Inject import-time deprecation warnings. Specifically, for ``literal_eval()``, ``_literal_eval()`` and ``get_exception()``. """ if importable_name == 'get_exception': deprecate( msg=f'The `ansible.module_utils.basic.' f'{importable_name}` function is deprecated.', version='2.19', ) from ansible.module_utils.pycompat24 import get_exception return get_exception if importable_name in {'literal_eval', '_literal_eval'}: deprecate( msg=f'The `ansible.module_utils.basic.' f'{importable_name}` function is deprecated.', version='2.19', ) from ast import literal_eval return literal_eval raise AttributeError( f'cannot import name {importable_name !r} ' f'has no attribute ({__file__ !s})', )
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
# # # # from __future__ import annotations try: import curses except ImportError: HAS_CURSES = False else: HAS_CURSES = True import collections.abc as c import codecs import ctypes.util import fcntl import getpass import io import logging
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
import os import random import subprocess import sys import termios import textwrap import threading import time import tty import typing as t from functools import wraps from struct import unpack, pack from ansible import constants as C from ansible.errors import AnsibleError, AnsibleAssertionError, AnsiblePromptInterrupt, AnsiblePromptNoninteractive from ansible.module_utils.common.text.converters import to_bytes, to_text from ansible.module_utils.six import text_type from ansible.utils.color import stringc from ansible.utils.multiprocessing import context as multiprocessing_context from ansible.utils.singleton import Singleton from ansible.utils.unsafe_proxy import wrap_var if t.TYPE_CHECKING: from ansible.executor.task_queue_manager import FinalQueue _LIBC = ctypes.cdll.LoadLibrary(ctypes.util.find_library('c')) _LIBC.wcwidth.argtypes = (ctypes.c_wchar,) _LIBC.wcswidth.argtypes = (ctypes.c_wchar_p, ctypes.c_int) _MAX_INT = 2 ** (ctypes.sizeof(ctypes.c_int) * 8 - 1) - 1 MOVE_TO_BOL = b'\r' CLEAR_TO_EOL = b'\x1b[K' def get_text_width(text: str) -> int:
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
"""Function that utilizes ``wcswidth`` or ``wcwidth`` to determine the number of columns used to display a text string. We try first with ``wcswidth``, and fallback to iterating each character and using wcwidth individually, falling back to a value of 0 for non-printable wide characters. """ if not isinstance(text, text_type): raise TypeError('get_text_width requires text, not %s' % type(text)) try: width = _LIBC.wcswidth(text, _MAX_INT) except ctypes.ArgumentError: width = -1 if width != -1: return width width = 0 counter = 0 for c in text: counter += 1 if c in (u'\x08', u'\x7f', u'\x94', u'\x1b'):
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
width -= 1 counter -= 1 continue try: w = _LIBC.wcwidth(c) except ctypes.ArgumentError: w = -1 if w == -1: w = 0 width += w if width == 0 and counter: raise EnvironmentError( 'get_text_width could not calculate text width of %r' % text ) return width if width >= 0 else 0 def proxy_display(method): def proxyit(self, *args, **kwargs): if self._final_q: return self._final_q.send_display(method.__name__, *args, **kwargs) else: return method(self, *args, **kwargs) return proxyit class FilterBlackList(logging.Filter):
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
def __init__(self, blacklist): self.blacklist = [logging.Filter(name) for name in blacklist] def filter(self, record): return not any(f.filter(record) for f in self.blacklist) class FilterUserInjector(logging.Filter): """ This is a filter which injects the current user as the 'user' attribute on each record. We need to add this filter to all logger handlers so that 3rd party libraries won't print an exception due to user not being defined. """ try: username = getpass.getuser() except KeyError: username = 'uid=%s' % os.getuid() def filter(self, record): record.user = FilterUserInjector.username return True logger = None if getattr(C, 'DEFAULT_LOG_PATH'): path = C.DEFAULT_LOG_PATH
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
if path and (os.path.exists(path) and os.access(path, os.W_OK)) or os.access(os.path.dirname(path), os.W_OK): logging.basicConfig(filename=path, level=logging.INFO, format='%(asctime)s p=%(process)d u=%(user)s n=%(name)s | %(message)s') logger = logging.getLogger('ansible') for handler in logging.root.handlers: handler.addFilter(FilterBlackList(getattr(C, 'DEFAULT_LOG_FILTER', []))) handler.addFilter(FilterUserInjector()) else: print("[WARNING]: log file at %s is not writeable and we cannot create it, aborting\n" % path, file=sys.stderr) color_to_log_level = {C.COLOR_ERROR: logging.ERROR, C.COLOR_WARN: logging.WARNING, C.COLOR_OK: logging.INFO, C.COLOR_SKIP: logging.WARNING, C.COLOR_UNREACHABLE: logging.ERROR, C.COLOR_DEBUG: logging.DEBUG, C.COLOR_CHANGED: logging.INFO, C.COLOR_DEPRECATE: logging.WARNING, C.COLOR_VERBOSE: logging.INFO} b_COW_PATHS = ( b"/usr/bin/cowsay", b"/usr/games/cowsay", b"/usr/local/bin/cowsay", b"/opt/local/bin/cowsay", ) def _synchronize_textiowrapper(tio: t.TextIO, lock: threading.RLock): def _wrap_with_lock(f, lock):
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
@wraps(f) def locking_wrapper(*args, **kwargs): with lock: return f(*args, **kwargs) return locking_wrapper buffer = tio.buffer buffer.write = _wrap_with_lock(buffer.write, lock) buffer.flush = _wrap_with_lock(buffer.flush, lock) def setraw(fd: int, when: int = termios.TCSAFLUSH) -> None: """Put terminal into a raw mode. Copied from ``tty`` from CPython 3.11.0, and modified to not remove OPOST from OFLAG OPOST is kept to prevent an issue with multi line prompts from being corrupted now that display is proxied via the queue from forks. The problem is a race condition, in that we proxy the display over the fork, but before it can be displayed, this plugin will have continued executing, potentially setting stdout and stdin to raw which remove output post processing that commonly converts NL to CRLF """ mode = termios.tcgetattr(fd) mode[tty.IFLAG] = mode[tty.IFLAG] & ~(termios.BRKINT | termios.ICRNL | termios.INPCK | termios.ISTRIP | termios.IXON) mode[tty.OFLAG] = mode[tty.OFLAG] & ~(termios.OPOST) mode[tty.CFLAG] = mode[tty.CFLAG] & ~(termios.CSIZE | termios.PARENB) mode[tty.CFLAG] = mode[tty.CFLAG] | termios.CS8 mode[tty.LFLAG] = mode[tty.LFLAG] & ~(termios.ECHO | termios.ICANON | termios.IEXTEN | termios.ISIG) mode[tty.CC][termios.VMIN] = 1 mode[tty.CC][termios.VTIME] = 0 termios.tcsetattr(fd, when, mode) def clear_line(stdout: t.BinaryIO) -> None:
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
stdout.write(b'\x1b[%s' % MOVE_TO_BOL) stdout.write(b'\x1b[%s' % CLEAR_TO_EOL) def setup_prompt(stdin_fd: int, stdout_fd: int, seconds: int, echo: bool) -> None: setraw(stdin_fd) if os.isatty(stdout_fd): setraw(stdout_fd) if echo: new_settings = termios.tcgetattr(stdin_fd) new_settings[3] = new_settings[3] | termios.ECHO termios.tcsetattr(stdin_fd, termios.TCSANOW, new_settings) def setupterm() -> None: try: curses.setupterm() except (curses.error, TypeError, io.UnsupportedOperation): global HAS_CURSES HAS_CURSES = False else: global MOVE_TO_BOL global CLEAR_TO_EOL MOVE_TO_BOL = curses.tigetstr('cr') or MOVE_TO_BOL CLEAR_TO_EOL = curses.tigetstr('el') or CLEAR_TO_EOL class Display(metaclass=Singleton): def __init__(self, verbosity: int = 0) -> None:
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
self._final_q: FinalQueue | None = None self._lock = threading.RLock() self.columns = None self.verbosity = verbosity if C.LOG_VERBOSITY is None: self.log_verbosity = verbosity else: self.log_verbosity = max(verbosity, C.LOG_VERBOSITY) self._deprecations: dict[str, int] = {} self._warns: dict[str, int] = {} self._errors: dict[str, int] = {} self.b_cowsay: bytes | None = None self.noncow = C.ANSIBLE_COW_SELECTION self.set_cowsay_info() if self.b_cowsay: try: cmd = subprocess.Popen([self.b_cowsay, "-l"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (out, err) = cmd.communicate() if cmd.returncode: raise Exception self.cows_available: set[str] = {to_text(c) for c in out.split()} if C.ANSIBLE_COW_ACCEPTLIST and any(C.ANSIBLE_COW_ACCEPTLIST): self.cows_available = set(C.ANSIBLE_COW_ACCEPTLIST).intersection(self.cows_available) except Exception: self.b_cowsay = None self._set_column_width()
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
try: _synchronize_textiowrapper(sys.stdout, self._lock) _synchronize_textiowrapper(sys.stderr, self._lock) except Exception as ex: self.warning(f"failed to patch stdout/stderr for fork-safety: {ex}") codecs.register_error('_replacing_warning_handler', self._replacing_warning_handler) try: sys.stdout.reconfigure(errors='_replacing_warning_handler') sys.stderr.reconfigure(errors='_replacing_warning_handler') except Exception as ex: self.warning(f"failed to reconfigure stdout/stderr with custom encoding error handler: {ex}") self.setup_curses = False def _replacing_warning_handler(self, exception: UnicodeError) -> tuple[str | bytes, int]: self.deprecated( 'Non UTF-8 encoded data replaced with "?" while displaying text to stdout/stderr, this is temporary and will become an error', version='2.18', ) return '?', exception.end def set_queue(self, queue: FinalQueue) -> None: """Set the _final_q on Display, so that we know to proxy display over the queue instead of directly writing to stdout/stderr from forks This is only needed in ansible.executor.process.worker:WorkerProcess._run """ if multiprocessing_context.parent_process() is None: raise RuntimeError('queue cannot be set in parent process') self._final_q = queue def set_cowsay_info(self) -> None:
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
if C.ANSIBLE_NOCOWS: return if C.ANSIBLE_COW_PATH: self.b_cowsay = C.ANSIBLE_COW_PATH else: for b_cow_path in b_COW_PATHS: if os.path.exists(b_cow_path): self.b_cowsay = b_cow_path @proxy_display def display( self, msg: str, color: str | None = None, stderr: bool = False, screen_only: bool = False, log_only: bool = False, newline: bool = True, ) -> None: """ Display a message to the user Note: msg *must* be a unicode string to prevent UnicodeError tracebacks. """ if not isinstance(msg, str): raise TypeError(f'Display message must be str, not: {msg.__class__.__name__}') nocolor = msg if not log_only: has_newline = msg.endswith(u'\n') if has_newline: msg2 = msg[:-1]
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
else: msg2 = msg if color: msg2 = stringc(msg2, color) if has_newline or newline: msg2 = msg2 + u'\n' if not stderr: fileobj = sys.stdout else: fileobj = sys.stderr with self._lock: fileobj.write(msg2) if logger and not screen_only: self._log(nocolor, color) @proxy_display def _log(self, msg: str, color: str | None = None, caplevel: int = 0):
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
if self.log_verbosity > caplevel: msg2 = msg.lstrip('\n') lvl = logging.INFO if color: try: lvl = color_to_log_level[color] except KeyError: raise AnsibleAssertionError('Invalid color supplied to display: %s' % color) logger.log(lvl, msg2) def v(self, msg: str, host: str | None = None) -> None: return self.verbose(msg, host=host, caplevel=0) def vv(self, msg: str, host: str | None = None) -> None: return self.verbose(msg, host=host, caplevel=1) def vvv(self, msg: str, host: str | None = None) -> None: return self.verbose(msg, host=host, caplevel=2) def vvvv(self, msg: str, host: str | None = None) -> None:
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
return self.verbose(msg, host=host, caplevel=3) def vvvvv(self, msg: str, host: str | None = None) -> None: return self.verbose(msg, host=host, caplevel=4) def vvvvvv(self, msg: str, host: str | None = None) -> None: return self.verbose(msg, host=host, caplevel=5) def debug(self, msg: str, host: str | None = None) -> None: if C.DEFAULT_DEBUG: if host is None: self.display("%6d %0.5f: %s" % (os.getpid(), time.time(), msg), color=C.COLOR_DEBUG) else: self.display("%6d %0.5f [%s]: %s" % (os.getpid(), time.time(), host, msg), color=C.COLOR_DEBUG) def verbose(self, msg: str, host: str | None = None, caplevel: int = 2) -> None: to_stderr = C.VERBOSE_TO_STDERR if self.verbosity > caplevel: if host is None: self.display(msg, color=C.COLOR_VERBOSE, stderr=to_stderr) else: self.display("<%s> %s" % (host, msg), color=C.COLOR_VERBOSE, stderr=to_stderr) elif self.log_verbosity > self.verbosity and self.log_verbosity > caplevel: if host is not None: msg = "<%s> %s" % (host, msg) self._log(msg, C.COLOR_VERBOSE, caplevel) def get_deprecation_message( self, msg: str, version: str | None = None, removed: bool = False, date: str | None = None, collection_name: str | None = None,
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
) -> str: ''' used to print out a deprecation message.''' msg = msg.strip() if msg and msg[-1] not in ['!', '?', '.']: msg += '.' if collection_name == 'ansible.builtin': collection_name = 'ansible-core' if removed: header = '[DEPRECATED]: {0}'.format(msg) removal_fragment = 'This feature was removed' help_text = 'Please update your playbooks.' else: header = '[DEPRECATION WARNING]: {0}'.format(msg) removal_fragment = 'This feature will be removed' help_text = 'Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.' if collection_name: from_fragment = 'from {0}'.format(collection_name) else: from_fragment = '' if date: when = 'in a release after {0}.'.format(date) elif version: when = 'in version {0}.'.format(version) else: when = 'in a future release.' message_text = ' '.join(f for f in [header, removal_fragment, from_fragment, when, help_text] if f) return message_text @proxy_display def deprecated(
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
self, msg: str, version: str | None = None, removed: bool = False, date: str | None = None, collection_name: str | None = None, ) -> None: if not removed and not C.DEPRECATION_WARNINGS: return message_text = self.get_deprecation_message(msg, version=version, removed=removed, date=date, collection_name=collection_name) if removed: raise AnsibleError(message_text) wrapped = textwrap.wrap(message_text, self.columns, drop_whitespace=False) message_text = "\n".join(wrapped) + "\n" if message_text not in self._deprecations: self.display(message_text.strip(), color=C.COLOR_DEPRECATE, stderr=True) self._deprecations[message_text] = 1 @proxy_display def warning(self, msg: str, formatted: bool = False) -> None: if not formatted: new_msg = "[WARNING]: %s" % msg wrapped = textwrap.wrap(new_msg, self.columns) new_msg = "\n".join(wrapped) + "\n" else: new_msg = "\n[WARNING]: \n%s" % msg if new_msg not in self._warns: self.display(new_msg, color=C.COLOR_WARN, stderr=True) self._warns[new_msg] = 1 def system_warning(self, msg: str) -> None:
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
if C.SYSTEM_WARNINGS: self.warning(msg) def banner(self, msg: str, color: str | None = None, cows: bool = True) -> None: ''' Prints a header-looking line with cowsay or stars with length depending on terminal width (3 minimum) ''' msg = to_text(msg) if self.b_cowsay and cows: try: self.banner_cowsay(msg) return except OSError: self.warning("somebody cleverly deleted cowsay or something during the PB run. heh.") msg = msg.strip() try: star_len = self.columns - get_text_width(msg) except EnvironmentError: star_len = self.columns - len(msg) if star_len <= 3: star_len = 3 stars = u"*" * star_len self.display(u"\n%s %s" % (msg, stars), color=color) def banner_cowsay(self, msg: str, color: str | None = None) -> None:
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
if u": [" in msg: msg = msg.replace(u"[", u"") if msg.endswith(u"]"): msg = msg[:-1] runcmd = [self.b_cowsay, b"-W", b"60"] if self.noncow: thecow = self.noncow if thecow == 'random': thecow = random.choice(list(self.cows_available)) runcmd.append(b'-f') runcmd.append(to_bytes(thecow)) runcmd.append(to_bytes(msg)) cmd = subprocess.Popen(runcmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (out, err) = cmd.communicate() self.display(u"%s\n" % to_text(out), color=color) def error(self, msg: str, wrap_text: bool = True) -> None: if wrap_text: new_msg = u"\n[ERROR]: %s" % msg wrapped = textwrap.wrap(new_msg, self.columns) new_msg = u"\n".join(wrapped) + u"\n" else: new_msg = u"ERROR! %s" % msg if new_msg not in self._errors: self.display(new_msg, color=C.COLOR_ERROR, stderr=True) self._errors[new_msg] = 1 @staticmethod def prompt(msg: str, private: bool = False) -> str:
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
if private: return getpass.getpass(msg) else: return input(msg) def do_var_prompt( self, varname: str, private: bool = True, prompt: str | None = None, encrypt: str | None = None, confirm: bool = False, salt_size: int | None = None, salt: str | None = None, default: str | None = None, unsafe: bool = False, ) -> str: result = None if sys.__stdin__.isatty(): do_prompt = self.prompt if prompt and default is not None:
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
msg = "%s [%s]: " % (prompt, default) elif prompt: msg = "%s: " % prompt else: msg = 'input for %s: ' % varname if confirm: while True: result = do_prompt(msg, private) second = do_prompt("confirm " + msg, private) if result == second: break self.display("***** VALUES ENTERED DO NOT MATCH ****") else: result = do_prompt(msg, private) else: result = None self.warning("Not prompting as we are not in interactive mode") if not result and default is not None: result = default if encrypt: from ansible.utils.encrypt import do_encrypt result = do_encrypt(result, encrypt, salt_size=salt_size, salt=salt) result = to_text(result, errors='surrogate_or_strict') if unsafe: result = wrap_var(result) return result def _set_column_width(self) -> None:
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
if os.isatty(1): tty_size = unpack('HHHH', fcntl.ioctl(1, termios.TIOCGWINSZ, pack('HHHH', 0, 0, 0, 0)))[1] else: tty_size = 0 self.columns = max(79, tty_size - 1) def prompt_until( self, msg: str, private: bool = False, seconds: int | None = None, interrupt_input: c.Container[bytes] | None = None, complete_input: c.Container[bytes] | None = None, ) -> bytes: if self._final_q: from ansible.executor.process.worker import current_worker self._final_q.send_prompt( worker_id=current_worker.worker_id, prompt=msg, private=private, seconds=seconds, interrupt_input=interrupt_input, complete_input=complete_input ) return current_worker.worker_queue.get() if HAS_CURSES and not self.setup_curses: setupterm() self.setup_curses = True if ( self._stdin_fd is None or not os.isatty(self._stdin_fd)
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
or os.getpgrp() != os.tcgetpgrp(self._stdin_fd) ): raise AnsiblePromptNoninteractive('stdin is not interactive') self.display(msg) result = b'' with self._lock: original_stdin_settings = termios.tcgetattr(self._stdin_fd) try: setup_prompt(self._stdin_fd, self._stdout_fd, seconds, not private) termios.tcflush(self._stdin, termios.TCIFLUSH) return self._read_non_blocking_stdin(echo=not private, seconds=seconds, interrupt_input=interrupt_input, complete_input=complete_input) finally: termios.tcsetattr(self._stdin_fd, termios.TCSADRAIN, original_stdin_settings) def _read_non_blocking_stdin(
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
self, echo: bool = False, seconds: int | None = None, interrupt_input: c.Container[bytes] | None = None, complete_input: c.Container[bytes] | None = None, ) -> bytes: if self._final_q: raise NotImplementedError if seconds is not None: start = time.time() if interrupt_input is None: try: interrupt = termios.tcgetattr(sys.stdin.buffer.fileno())[6][termios.VINTR] except Exception: interrupt = b'\x03' try: backspace_sequences = [termios.tcgetattr(self._stdin_fd)[6][termios.VERASE]] except Exception: backspace_sequences = [b'\x7f', b'\x08']
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
result_string = b'' while seconds is None or (time.time() - start < seconds): key_pressed = None try: os.set_blocking(self._stdin_fd, False) while key_pressed is None and (seconds is None or (time.time() - start < seconds)): key_pressed = self._stdin.read(1) time.sleep(C.DEFAULT_INTERNAL_POLL_INTERVAL) finally: os.set_blocking(self._stdin_fd, True) if key_pressed is None: key_pressed = b'' if (interrupt_input is None and key_pressed == interrupt) or (interrupt_input is not None and key_pressed.lower() in interrupt_input): clear_line(self._stdout) raise AnsiblePromptInterrupt('user interrupt') if (complete_input is None and key_pressed in (b'\r', b'\n')) or (complete_input is not None and key_pressed.lower() in complete_input): clear_line(self._stdout) break elif key_pressed in backspace_sequences: clear_line(self._stdout) result_string = result_string[:-1] if echo: self._stdout.write(result_string) self._stdout.flush() else: result_string += key_pressed return result_string @property def _stdin(self) -> t.BinaryIO | None:
closed
ansible/ansible
https://github.com/ansible/ansible
82,226
ANSIBLE_LOG_PATH no longer works since #81692 got merged
### Summary If you run `ANSIBLE_LOG_PATH=test ansible localhost -m setup`, `test` is now an empty file. Before #81692 got merged, it contained log output like ``` 023-11-16 08:01:52,262 p=313108 u=felix n=ansible | [WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any point. 2023-11-16 08:01:52,383 p=313108 u=felix n=ansible | [WARNING]: No inventory was parsed, only implicit localhost is available 2023-11-16 08:01:53,511 p=313108 u=felix n=ansible | localhost | SUCCESS => { "ansible_facts": { ... ``` ### Issue Type Bug Report ### Component Name logging ### Ansible Version ```console latest devel branch ``` ### Configuration ```console - ``` ### OS / Environment - ### Steps to Reproduce Run `ANSIBLE_LOG_PATH=test ansible localhost -m setup` ### Expected Results File `test` contains log output. ### Actual Results ```console File `test` is empty. ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/82226
https://github.com/ansible/ansible/pull/82227
f8cdec632461fbd821050fc584543c1dda6dfc5c
f6d7dd0840c079d0d2c2e3d8852b952462423a78
2023-11-16T07:03:17Z
python
2023-11-16T19:49:40Z
lib/ansible/utils/display.py
if self._final_q: raise NotImplementedError try: return sys.stdin.buffer except AttributeError: return None @property def _stdin_fd(self) -> int | None: try: return self._stdin.fileno() except (ValueError, AttributeError): return None @property def _stdout(self) -> t.BinaryIO: if self._final_q: raise NotImplementedError return sys.stdout.buffer @property def _stdout_fd(self) -> int | None: try: return self._stdout.fileno() except (ValueError, AttributeError): return None
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
from __future__ import annotations DOCUMENTATION = r''' --- module: wait_for short_description: Waits for a condition before continuing description: - You can wait for a set amount of time O(timeout), this is the default if nothing is specified or just O(timeout) is specified. This does not produce an error. - Waiting for a port to become available is useful for when services are not immediately available after their init scripts return which is true of certain Java application servers. - It is also useful when starting guests with the M(community.libvirt.virt) module and needing to pause until they are ready. - This module can also be used to wait for a regex match a string to be present in a file. - In Ansible 1.6 and later, this module can also be used to wait for a file to be available or absent on the filesystem. - In Ansible 1.8 and later, this module can also be used to wait for active connections to be closed before continuing, useful if a node is being rotated out of a load balancer pool. - For Windows targets, use the M(ansible.windows.win_wait_for) module instead. version_added: "0.7"
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
options: host: description: - A resolvable hostname or IP address to wait for. type: str default: 127.0.0.1 timeout: description: - Maximum number of seconds to wait for, when used with another condition it will force an error. - When used without other conditions it is equivalent of just sleeping. type: int default: 300 connect_timeout: description: - Maximum number of seconds to wait for a connection to happen before closing and retrying. type: int default: 5 delay: description: - Number of seconds to wait before starting to poll. type: int default: 0 port: description: - Port number to poll. - O(path) and O(port) are mutually exclusive parameters. type: int active_connection_states: description: - The list of TCP connection states which are counted as active connections.
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
type: list elements: str default: [ ESTABLISHED, FIN_WAIT1, FIN_WAIT2, SYN_RECV, SYN_SENT, TIME_WAIT ] version_added: "2.3" state: description: - Either V(present), V(started), or V(stopped), V(absent), or V(drained). - When checking a port V(started) will ensure the port is open, V(stopped) will check that it is closed, V(drained) will check for active connections. - When checking for a file or a search string V(present) or V(started) will ensure that the file or string is present before continuing, V(absent) will check that file is absent or removed. type: str choices: [ absent, drained, present, started, stopped ] default: started path: description: - Path to a file on the filesystem that must exist before continuing. - O(path) and O(port) are mutually exclusive parameters. type: path version_added: "1.4" search_regex: description: - Can be used to match a string in either a file or a socket connection. - Defaults to a multiline regex. type: str version_added: "1.4" exclude_hosts: description: - List of hosts or IPs to ignore when looking for active TCP connections for V(drained) state. type: list elements: str
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
version_added: "1.8" sleep: description: - Number of seconds to sleep between checks. - Before Ansible 2.3 this was hardcoded to 1 second. type: int default: 1 version_added: "2.3" msg: description: - This overrides the normal error message from a failure to meet the required conditions. type: str version_added: "2.4" extends_documentation_fragment: action_common_attributes attributes: check_mode: support: none diff_mode: support: none platform: platforms: posix notes: - The ability to use search_regex with a port connection was added in Ansible 1.7. - Prior to Ansible 2.4, testing for the absence of a directory or UNIX socket did not work correctly. - Prior to Ansible 2.4, testing for the presence of a file did not work correctly if the remote user did not have read access to that file. - Under some circumstances when using mandatory access control, a path may always be treated as being absent even if it exists, but can't be modified or created by the remote user either. - When waiting for a path, symbolic links will be followed. Many other modules that manipulate files do not follow symbolic links, so operations on the path using other modules may not work exactly as expected. seealso:
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
- module: ansible.builtin.wait_for_connection - module: ansible.windows.win_wait_for - module: community.windows.win_wait_for_process author: - Jeroen Hoekx (@jhoekx) - John Jarvis (@jarv) - Andrii Radyk (@AnderEnder) ''' EXAMPLES = r''' - name: Sleep for 300 seconds and continue with play ansible.builtin.wait_for: timeout: 300 delegate_to: localhost - name: Wait for port 8000 to become open on the host, don't start checking for 10 seconds ansible.builtin.wait_for: port: 8000 delay: 10 - name: Waits for port 8000 of any IP to close active connections, don't start checking for 10 seconds ansible.builtin.wait_for: host: 0.0.0.0 port: 8000 delay: 10 state: drained - name: Wait for port 8000 of any IP to close active connections, ignoring connections for specified hosts ansible.builtin.wait_for: host: 0.0.0.0 port: 8000 state: drained exclude_hosts: 10.2.1.2,10.2.1.3 - name: Wait until the file /tmp/foo is present before continuing
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
ansible.builtin.wait_for: path: /tmp/foo - name: Wait until the string "completed" is in the file /tmp/foo before continuing ansible.builtin.wait_for: path: /tmp/foo search_regex: completed - name: Wait until regex pattern matches in the file /tmp/foo and print the matched group ansible.builtin.wait_for: path: /tmp/foo search_regex: completed (?P<task>\w+) register: waitfor - ansible.builtin.debug: msg: Completed {{ waitfor['match_groupdict']['task'] }} - name: Wait until the lock file is removed ansible.builtin.wait_for: path: /var/lock/file.lock state: absent - name: Wait until the process is finished and pid was destroyed ansible.builtin.wait_for: path: /proc/3466/status state: absent - name: Output customized message when failed ansible.builtin.wait_for: path: /tmp/foo state: present msg: Timeout to find file /tmp/foo # Do not assume the inventory_hostname is resolvable and delay 10 seconds at start - name: Wait 300 seconds for port 22 to become open and contain "OpenSSH" ansible.builtin.wait_for: port: 22
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}' search_regex: OpenSSH delay: 10 connection: local # Same as above but you normally have ansible_connection set in inventory, which overrides 'connection' - name: Wait 300 seconds for port 22 to become open and contain "OpenSSH" ansible.builtin.wait_for: port: 22 host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}' search_regex: OpenSSH delay: 10 vars: ansible_connection: local ''' RETURN = r''' elapsed: description: The number of seconds that elapsed while waiting returned: always type: int sample: 23 match_groups: description: Tuple containing all the subgroups of the match as returned by U(https://docs.python.org/3/library/re.html#re.MatchObject.groups) returned: always type: list sample: ['match 1', 'match 2'] match_groupdict: description: Dictionary containing all the named subgroups of the match, keyed by the subgroup name, as returned by U(https://docs.python.org/3/library/re.html#re.MatchObject.groupdict) returned: always type: dict
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
sample: { 'group': 'match' } ''' import binascii import contextlib import datetime import errno import math import mmap import os import re import select import socket import time import traceback from ansible.module_utils.basic import AnsibleModule, missing_required_lib from ansible.module_utils.common.sys_info import get_platform_subclass from ansible.module_utils.common.text.converters import to_bytes from ansible.module_utils.compat.datetime import utcnow HAS_PSUTIL = False PSUTIL_IMP_ERR = None try: import psutil HAS_PSUTIL = True except ImportError: PSUTIL_IMP_ERR = traceback.format_exc() class TCPConnectionInfo(object):
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
""" This is a generic TCP Connection Info strategy class that relies on the psutil module, which is not ideal for targets, but necessary for cross platform support. A subclass may wish to override some or all of these methods. - _get_exclude_ips() - get_active_connections() All subclasses MUST define platform and distribution (which may be None). """ platform = 'Generic' distribution = None match_all_ips = { socket.AF_INET: '0.0.0.0', socket.AF_INET6: '::', } ipv4_mapped_ipv6_address = { 'prefix': '::ffff', 'match_all': '::ffff:0.0.0.0' } def __new__(cls, *args, **kwargs):
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
new_cls = get_platform_subclass(TCPConnectionInfo) return super(cls, new_cls).__new__(new_cls) def __init__(self, module): self.module = module self.ips = _convert_host_to_ip(module.params['host']) self.port = int(self.module.params['port']) self.exclude_ips = self._get_exclude_ips() if not HAS_PSUTIL: module.fail_json(msg=missing_required_lib('psutil'), exception=PSUTIL_IMP_ERR) def _get_exclude_ips(self): exclude_hosts = self.module.params['exclude_hosts'] exclude_ips = [] if exclude_hosts is not None: for host in exclude_hosts: exclude_ips.extend(_convert_host_to_ip(host)) return exclude_ips def get_active_connections_count(self): active_connections = 0 for p in psutil.process_iter(): try: if hasattr(p, 'get_connections'):
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
connections = p.get_connections(kind='inet') else: connections = p.connections(kind='inet') except psutil.Error: continue for conn in connections: if conn.status not in self.module.params['active_connection_states']: continue if hasattr(conn, 'local_address'): (local_ip, local_port) = conn.local_address else: (local_ip, local_port) = conn.laddr if self.port != local_port: continue if hasattr(conn, 'remote_address'): (remote_ip, remote_port) = conn.remote_address else: (remote_ip, remote_port) = conn.raddr if (conn.family, remote_ip) in self.exclude_ips: continue if any(( (conn.family, local_ip) in self.ips, (conn.family, self.match_all_ips[conn.family]) in self.ips, local_ip.startswith(self.ipv4_mapped_ipv6_address['prefix']) and (conn.family, self.ipv4_mapped_ipv6_address['match_all']) in self.ips, )): active_connections += 1 return active_connections class LinuxTCPConnectionInfo(TCPConnectionInfo):
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
""" This is a TCP Connection Info evaluation strategy class that utilizes information from Linux's procfs. While less universal, does allow Linux targets to not require an additional library. """ platform = 'Linux' distribution = None source_file = { socket.AF_INET: '/proc/net/tcp', socket.AF_INET6: '/proc/net/tcp6' } match_all_ips = { socket.AF_INET: '00000000', socket.AF_INET6: '00000000000000000000000000000000', } ipv4_mapped_ipv6_address = { 'prefix': '0000000000000000FFFF0000', 'match_all': '0000000000000000FFFF000000000000' } local_address_field = 1 remote_address_field = 2 connection_state_field = 3 def __init__(self, module):
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
self.module = module self.ips = _convert_host_to_hex(module.params['host']) self.port = "%0.4X" % int(module.params['port']) self.exclude_ips = self._get_exclude_ips() def _get_exclude_ips(self): exclude_hosts = self.module.params['exclude_hosts'] exclude_ips = [] if exclude_hosts is not None: for host in exclude_hosts: exclude_ips.extend(_convert_host_to_hex(host)) return exclude_ips def get_active_connections_count(self): active_connections = 0 for family in self.source_file.keys(): if not os.path.isfile(self.source_file[family]): continue try: f = open(self.source_file[family]) for tcp_connection in f.readlines(): tcp_connection = tcp_connection.strip().split() if tcp_connection[self.local_address_field] == 'local_address': continue if (tcp_connection[self.connection_state_field] not in [get_connection_state_id(_connection_state) for _connection_state in self.module.params['active_connection_states']]): continue (local_ip, local_port) = tcp_connection[self.local_address_field].split(':') if self.port != local_port: continue (remote_ip, remote_port) = tcp_connection[self.remote_address_field].split(':') if (family, remote_ip) in self.exclude_ips:
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
continue if any(( (family, local_ip) in self.ips, (family, self.match_all_ips[family]) in self.ips, local_ip.startswith(self.ipv4_mapped_ipv6_address['prefix']) and (family, self.ipv4_mapped_ipv6_address['match_all']) in self.ips, )): active_connections += 1 except IOError as e: pass finally: f.close() return active_connections def _convert_host_to_ip(host): """ Perform forward DNS resolution on host, IP will give the same IP Args: host: String with either hostname, IPv4, or IPv6 address Returns: List of tuples containing address family and IP """ addrinfo = socket.getaddrinfo(host, 80, 0, 0, socket.SOL_TCP) ips = [] for family, socktype, proto, canonname, sockaddr in addrinfo: ip = sockaddr[0] ips.append((family, ip)) if family == socket.AF_INET: ips.append((socket.AF_INET6, "::ffff:" + ip)) return ips def _convert_host_to_hex(host):
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
""" Convert the provided host to the format in /proc/net/tcp* /proc/net/tcp uses little-endian four byte hex for ipv4 /proc/net/tcp6 uses little-endian per 4B word for ipv6 Args: host: String with either hostname, IPv4, or IPv6 address Returns: List of tuples containing address family and the little-endian converted host """ ips = [] if host is not None: for family, ip in _convert_host_to_ip(host): hexip_nf = binascii.b2a_hex(socket.inet_pton(family, ip)) hexip_hf = "" for i in range(0, len(hexip_nf), 8): ipgroup_nf = hexip_nf[i:i + 8] ipgroup_hf = socket.ntohl(int(ipgroup_nf, base=16)) hexip_hf = "%s%08X" % (hexip_hf, ipgroup_hf) ips.append((family, hexip_hf)) return ips def _timedelta_total_seconds(timedelta):
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
return ( timedelta.microseconds + 0.0 + (timedelta.seconds + timedelta.days * 24 * 3600) * 10 ** 6) / 10 ** 6 def get_connection_state_id(state): connection_state_id = { 'ESTABLISHED': '01', 'SYN_SENT': '02', 'SYN_RECV': '03', 'FIN_WAIT1': '04', 'FIN_WAIT2': '05', 'TIME_WAIT': '06', } return connection_state_id[state] def main(): module = AnsibleModule( argument_spec=dict( host=dict(type='str', default='127.0.0.1'), timeout=dict(type='int', default=300), connect_timeout=dict(type='int', default=5), delay=dict(type='int', default=0), port=dict(type='int'), active_connection_states=dict(type='list', elements='str', default=['ESTABLISHED', 'FIN_WAIT1', 'FIN_WAIT2', 'SYN_RECV', 'SYN_SENT', 'TIME_WAIT']), path=dict(type='path'), search_regex=dict(type='str'), state=dict(type='str', default='started', choices=['absent', 'drained', 'present', 'started', 'stopped']), exclude_hosts=dict(type='list', elements='str'),
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
sleep=dict(type='int', default=1), msg=dict(type='str'), ), ) host = module.params['host'] timeout = module.params['timeout'] connect_timeout = module.params['connect_timeout'] delay = module.params['delay'] port = module.params['port'] state = module.params['state'] path = module.params['path'] b_path = to_bytes(path, errors='surrogate_or_strict', nonstring='passthru') search_regex = module.params['search_regex'] b_search_regex = to_bytes(search_regex, errors='surrogate_or_strict', nonstring='passthru') msg = module.params['msg'] if search_regex is not None: try: b_compiled_search_re = re.compile(b_search_regex, re.MULTILINE) except re.error as e: module.fail_json(msg="Invalid regular expression: %s" % e) else: b_compiled_search_re = None match_groupdict = {} match_groups = () if port and path: module.fail_json(msg="port and path parameter can not both be passed to wait_for", elapsed=0) if path and state == 'stopped': module.fail_json(msg="state=stopped should only be used for checking a port in the wait_for module", elapsed=0) if path and state == 'drained': module.fail_json(msg="state=drained should only be used for checking a port in the wait_for module", elapsed=0)
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
if module.params['exclude_hosts'] is not None and state != 'drained': module.fail_json(msg="exclude_hosts should only be with state=drained", elapsed=0) for _connection_state in module.params['active_connection_states']: try: get_connection_state_id(_connection_state) except Exception: module.fail_json(msg="unknown active_connection_state (%s) defined" % _connection_state, elapsed=0) start = utcnow() if delay: time.sleep(delay) if not port and not path and state != 'drained': time.sleep(timeout) elif state in ['absent', 'stopped']: end = start + datetime.timedelta(seconds=timeout) while utcnow() < end: if path: try: if not os.access(b_path, os.F_OK): break except IOError: break elif port: try: s = socket.create_connection((host, port), connect_timeout) s.shutdown(socket.SHUT_RDWR) s.close() except Exception: break
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
time.sleep(module.params['sleep']) else: elapsed = utcnow() - start if port: module.fail_json(msg=msg or "Timeout when waiting for %s:%s to stop." % (host, port), elapsed=elapsed.seconds) elif path: module.fail_json(msg=msg or "Timeout when waiting for %s to be absent." % (path), elapsed=elapsed.seconds) elif state in ['started', 'present']: end = start + datetime.timedelta(seconds=timeout) while utcnow() < end: if path: try: os.stat(b_path) except OSError as e: if e.errno != 2: elapsed = utcnow() - start module.fail_json(msg=msg or "Failed to stat %s, %s" % (path, e.strerror), elapsed=elapsed.seconds) else: if not b_compiled_search_re: break try: with open(b_path, 'rb') as f: with contextlib.closing(mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)) as mm: search = b_compiled_search_re.search(mm) if search:
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
if search.groupdict(): match_groupdict = search.groupdict() if search.groups(): match_groups = search.groups() break except IOError: pass elif port: alt_connect_timeout = math.ceil(_timedelta_total_seconds(end - utcnow())) try: s = socket.create_connection((host, port), min(connect_timeout, alt_connect_timeout)) except Exception: pass else: if b_compiled_search_re: b_data = b'' matched = False while utcnow() < end: max_timeout = math.ceil(_timedelta_total_seconds(end - utcnow())) readable = select.select([s], [], [], max_timeout)[0] if not readable: continue response = s.recv(1024) if not response: break
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
b_data += response if b_compiled_search_re.search(b_data): matched = True break try: s.shutdown(socket.SHUT_RDWR) except socket.error as e: if e.errno != errno.ENOTCONN: raise else: s.close() if matched: break else: try: s.shutdown(socket.SHUT_RDWR) except socket.error as e: if e.errno != errno.ENOTCONN: raise else: s.close() break time.sleep(module.params['sleep']) else:
closed
ansible/ansible
https://github.com/ansible/ansible
79,683
wait_for no longer works for files in e.g. sysfs because it uses mmap() instead of read()
### Summary We have an ansible task using `wait_for` module to wait for network device carrier to be up: ``` wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` This no longer works since https://github.com/ansible/ansible/commit/9d4ced1237380051334b54379ff64e45c0341a6d, because `mmap()` is now used instead of `read()`, and it isn't supported by `sysfs` in this case. Do we really need to use `mmap()`? I imagine it might cause issues with other pseudofilesystems too. In the meantime, we use a workaround: use grep in a loop instead ``` command: cmd: "grep 1 /sys/class/net/{{ device }}/carrier" timeout: 1 retries: 60 register: carrier until: carrier is successful ``` ### Issue Type Bug Report ### Component Name wait_for ### Ansible Version ```console $ ansible --version ansible [core 2.13.7] config file = None configured module search path = ['/Users/rob.muir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /Users/rob.muir/workspace/trash/build/.env/lib/python3.10/site-packages/ansible ansible collection location = /Users/rob.muir/.ansible/collections:/usr/share/ansible/collections executable location = /Users/rob.muir/workspace/trash/build/.env/bin/ansible python version = 3.10.7 (main, Sep 15 2022, 01:50:27) [Clang 12.0.0 (clang-1200.0.32.29)] jinja version = 3.0.3 libyaml = False ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all ``` ### OS / Environment Mac OS controller, Centos Stream 9 target ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ``` # set device to say, eth0 or whatever is on your computer wait_for: path: "/sys/class/net/{{ device }}/carrier" search_regex: "1" timeout: 60 ``` ### Expected Results Expect wait_for to still work with files in /sys ### Actual Results ```console The wait_for will fail, only with recent ansible versions, due to the use of mmap() ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/79683
https://github.com/ansible/ansible/pull/82064
f6d7dd0840c079d0d2c2e3d8852b952462423a78
8b102dca4a236efcf645e8c17721da549cda61c5
2023-01-06T15:47:11Z
python
2023-11-16T20:20:52Z
lib/ansible/modules/wait_for.py
elapsed = utcnow() - start if port: if search_regex: module.fail_json(msg=msg or "Timeout when waiting for search string %s in %s:%s" % (search_regex, host, port), elapsed=elapsed.seconds) else: module.fail_json(msg=msg or "Timeout when waiting for %s:%s" % (host, port), elapsed=elapsed.seconds) elif path: if search_regex: module.fail_json(msg=msg or "Timeout when waiting for search string %s in %s" % (search_regex, path), elapsed=elapsed.seconds) else: module.fail_json(msg=msg or "Timeout when waiting for file %s" % (path), elapsed=elapsed.seconds) elif state == 'drained': end = start + datetime.timedelta(seconds=timeout) tcpconns = TCPConnectionInfo(module) while utcnow() < end: if tcpconns.get_active_connections_count() == 0: break time.sleep(module.params['sleep']) else: elapsed = utcnow() - start module.fail_json(msg=msg or "Timeout when waiting for %s:%s to drain" % (host, port), elapsed=elapsed.seconds) elapsed = utcnow() - start module.exit_json(state=state, port=port, search_regex=search_regex, match_groups=match_groups, match_groupdict=match_groupdict, path=path, elapsed=elapsed.seconds) if __name__ == '__main__': main()
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
from __future__ import annotations DOCUMENTATION = r''' --- module: unarchive version_added: '1.4' short_description: Unpacks an archive after (optionally) copying it from the local machine description: - The M(ansible.builtin.unarchive) module unpacks an archive. It will not unpack a compressed file that does not contain an archive. - By default, it will copy the source file from the local system to the target before unpacking. - Set O(remote_src=yes) to unpack an archive which already exists on the target. - If checksum validation is desired, use M(ansible.builtin.get_url) or M(ansible.builtin.uri) instead to fetch the file and set O(remote_src=yes). - For Windows targets, use the M(community.windows.win_unzip) module instead. options: src: description: - If O(remote_src=no) (default), local path to archive file to copy to the target server; can be absolute or relative. If O(remote_src=yes), path on the target server to existing archive file to unpack. - If O(remote_src=yes) and O(src) contains V(://), the remote machine will download the file from the URL first. (version_added 2.0). This is only for simple cases, for full download support use the M(ansible.builtin.get_url) module. type: path required: true dest:
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
description: - Remote absolute path where the archive should be unpacked. - The given path must exist. Base directory is not created by this module. type: path required: true copy: description: - If true, the file is copied from local controller to the managed (remote) node, otherwise, the plugin will look for src archive on the managed machine. - This option has been deprecated in favor of O(remote_src). - This option is mutually exclusive with O(remote_src). type: bool default: yes creates: description: - If the specified absolute path (file or directory) already exists, this step will B(not) be run. - The specified absolute path (file or directory) must be below the base path given with O(dest). type: path version_added: "1.6" io_buffer_size: description: - Size of the volatile memory buffer that is used for extracting files from the archive in bytes. type: int default: 65536 version_added: "2.12" list_files: description: - If set to True, return the list of files that are contained in the tarball. type: bool default: no version_added: "2.0"
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
exclude: description: - List the directory and file entries that you would like to exclude from the unarchive action. - Mutually exclusive with O(include). type: list default: [] elements: str version_added: "2.1" include: description: - List of directory and file entries that you would like to extract from the archive. If O(include) is not empty, only files listed here will be extracted. - Mutually exclusive with O(exclude). type: list default: [] elements: str version_added: "2.11" keep_newer: description: - Do not replace existing files that are newer than files from the archive. type: bool default: no version_added: "2.1" extra_opts: description: - Specify additional options by passing in an array. - Each space-separated command-line option should be a new element of the array. See examples. - Command-line options with multiple elements must use multiple lines in the array, one for each element. type: list elements: str
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
default: [] version_added: "2.1" remote_src: description: - Set to V(true) to indicate the archived file is already on the remote system and not local to the Ansible controller. - This option is mutually exclusive with O(copy). type: bool default: no version_added: "2.2" validate_certs: description: - This only applies if using a https URL as the source of the file. - This should only set to V(false) used on personally controlled sites using self-signed certificate. - Prior to 2.2 the code worked as if this was set to V(true). type: bool default: yes version_added: "2.2" extends_documentation_fragment: - action_common_attributes - action_common_attributes.flow - action_common_attributes.files - decrypt - files attributes: action: support: full async: support: none bypass_host_loop: support: none
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
check_mode: support: partial details: Not supported for gzipped tar files. diff_mode: support: partial details: Uses gtar's C(--diff) arg to calculate if changed or not. If this C(arg) is not supported, it will always unpack the archive. platform: platforms: posix safe_file_operations: support: none vault: support: full todo: - Re-implement tar support using native tarfile module. - Re-implement zip support using native zipfile module. notes: - Requires C(zipinfo) and C(gtar)/C(unzip) command on target host. - Requires C(zstd) command on target host to expand I(.tar.zst) files. - Can handle I(.zip) files using C(unzip) as well as I(.tar), I(.tar.gz), I(.tar.bz2), I(.tar.xz), and I(.tar.zst) files using C(gtar). - Does not handle I(.gz) files, I(.bz2) files, I(.xz), or I(.zst) files that do not contain a I(.tar) archive. - Existing files/directories in the destination which are not in the archive are not touched. This is the same behavior as a normal archive extraction. - Existing files/directories in the destination which are not in the archive are ignored for purposes of deciding if the archive should be unpacked or not. seealso: - module: community.general.archive - module: community.general.iso_extract - module: community.windows.win_unzip author: Michael DeHaan '''
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
EXAMPLES = r''' - name: Extract foo.tgz into /var/lib/foo ansible.builtin.unarchive: src: foo.tgz dest: /var/lib/foo - name: Unarchive a file that is already on the remote machine ansible.builtin.unarchive: src: /tmp/foo.zip dest: /usr/local/bin remote_src: yes - name: Unarchive a file that needs to be downloaded (added in 2.0) ansible.builtin.unarchive: src: https://example.com/example.zip dest: /usr/local/bin remote_src: yes - name: Unarchive a file with extra options ansible.builtin.unarchive: src: /tmp/foo.zip dest: /usr/local/bin extra_opts: - --transform - s/^xxx/yyy/ ''' RETURN = r''' dest: description: Path to the destination directory. returned: always type: str sample: /opt/software files:
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
description: List of all the files in the archive. returned: When O(list_files) is V(True) type: list sample: '["file1", "file2"]' gid: description: Numerical ID of the group that owns the destination directory. returned: always type: int sample: 1000 group: description: Name of the group that owns the destination directory. returned: always type: str sample: "librarians" handler: description: Archive software handler used to extract and decompress the archive. returned: always type: str sample: "TgzArchive" mode: description: String that represents the octal permissions of the destination directory. returned: always type: str sample: "0755" owner: description: Name of the user that owns the destination directory. returned: always type: str sample: "paul" size:
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
description: The size of destination directory in bytes. Does not include the size of files or subdirectories contained within. returned: always type: int sample: 36 src: description: - The source archive's path. - If O(src) was a remote web URL, or from the local ansible controller, this shows the temporary location where the download was stored. returned: always type: str sample: "/home/paul/test.tar.gz" state: description: State of the destination. Effectively always "directory". returned: always type: str sample: "directory" uid: description: Numerical ID of the user that owns the destination directory. returned: always type: int sample: 1000 ''' import binascii import codecs import datetime import fnmatch import grp import os import platform import pwd
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
import re import stat import time import traceback from functools import partial from zipfile import ZipFile from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.process import get_bin_path from ansible.module_utils.common.locale import get_best_parsable_locale from ansible.module_utils.urls import fetch_file try: from shlex import quote except ImportError: from pipes import quote try: from zipfile import BadZipFile except ImportError: from zipfile import BadZipfile as BadZipFile OWNER_DIFF_RE = re.compile(r': Uid differs$') GROUP_DIFF_RE = re.compile(r': Gid differs$') MODE_DIFF_RE = re.compile(r': Mode differs$') MOD_TIME_DIFF_RE = re.compile(r': Mod time differs$') EMPTY_FILE_RE = re.compile(r': : Warning: Cannot stat: No such file or directory$') MISSING_FILE_RE = re.compile(r': Warning: Cannot stat: No such file or directory$') ZIP_FILE_MODE_RE = re.compile(r'([r-][w-][SsTtx-]){3}') INVALID_OWNER_RE = re.compile(r': Invalid owner') INVALID_GROUP_RE = re.compile(r': Invalid group') SYMLINK_DIFF_RE = re.compile(r': Symlink differs$') def crc32(path, buffer_size):
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
''' Return a CRC32 checksum of a file ''' crc = binascii.crc32(b'') with open(path, 'rb') as f: for b_block in iter(partial(f.read, buffer_size), b''): crc = binascii.crc32(b_block, crc) return crc & 0xffffffff def shell_escape(string): ''' Quote meta-characters in the args for the unix shell ''' return re.sub(r'([^A-Za-z0-9_])', r'\\\1', string) class UnarchiveError(Exception): pass class ZipArchive(object):
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
def __init__(self, src, b_dest, file_args, module): self.src = src self.b_dest = b_dest self.file_args = file_args self.opts = module.params['extra_opts'] self.module = module self.io_buffer_size = module.params["io_buffer_size"] self.excludes = module.params['exclude'] self.includes = [] self.include_files = self.module.params['include'] self.cmd_path = None self.zipinfo_cmd_path = None self._files_in_archive = [] self._infodict = dict() self.zipinfoflag = '' self.binaries = ( ('unzip', 'cmd_path'), ('zipinfo', 'zipinfo_cmd_path'), ) def _permstr_to_octal(self, modestr, umask): ''' Convert a Unix permission string (rw-r--r--) into a mode (0644) ''' revstr = modestr[::-1] mode = 0 for j in range(0, 3): for i in range(0, 3): if revstr[i + 3 * j] in ['r', 'w', 'x', 's', 't']: mode += 2 ** (i + 3 * j) return (mode & ~umask) def _legacy_file_list(self):
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
rc, out, err = self.module.run_command([self.cmd_path, '-v', self.src]) if rc: self.module.debug(err) raise UnarchiveError('Neither python zipfile nor unzip can read %s' % self.src) for line in out.splitlines()[3:-2]: fields = line.split(None, 7) self._files_in_archive.append(fields[7]) self._infodict[fields[7]] = int(fields[6]) def _crc32(self, path): if self._infodict: return self._infodict[path] try: archive = ZipFile(self.src) except BadZipFile as e: if e.args[0].lower().startswith('bad magic number'): self._legacy_file_list() else: raise else: try: for item in archive.infolist(): self._infodict[item.filename] = int(item.CRC) except Exception: archive.close() raise UnarchiveError('Unable to list files in the archive') return self._infodict[path] @property def files_in_archive(self):
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
if self._files_in_archive: return self._files_in_archive self._files_in_archive = [] try: archive = ZipFile(self.src) except BadZipFile as e: if e.args[0].lower().startswith('bad magic number'): self._legacy_file_list() else: raise else: try: for member in archive.namelist(): if self.include_files: for include in self.include_files: if fnmatch.fnmatch(member, include): self._files_in_archive.append(to_native(member)) else: exclude_flag = False if self.excludes: for exclude in self.excludes: if fnmatch.fnmatch(member, exclude): exclude_flag = True break if not exclude_flag: self._files_in_archive.append(to_native(member)) except Exception as e: archive.close()
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
raise UnarchiveError('Unable to list files in the archive: %s' % to_native(e)) archive.close() return self._files_in_archive def is_unarchived(self): if self.zipinfoflag: cmd = [self.zipinfo_cmd_path, self.zipinfoflag, '-T', '-s', self.src] else: cmd = [self.zipinfo_cmd_path, '-T', '-s', self.src] if self.excludes: cmd.extend(['-x', ] + self.excludes) if self.include_files: cmd.extend(self.include_files) rc, out, err = self.module.run_command(cmd) self.module.debug(err) old_out = out diff = '' out = '' if rc == 0: unarchived = True else: unarchived = False umask = os.umask(0) os.umask(umask) systemtype = platform.system() groups = os.getgroups() run_uid = os.getuid() run_gid = os.getgid()
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
try: run_owner = pwd.getpwuid(run_uid).pw_name except (TypeError, KeyError): run_owner = run_uid try: run_group = grp.getgrgid(run_gid).gr_name except (KeyError, ValueError, OverflowError): run_group = run_gid fut_owner = fut_uid = None if self.file_args['owner']: try: tpw = pwd.getpwnam(self.file_args['owner']) except KeyError: try: tpw = pwd.getpwuid(int(self.file_args['owner'])) except (TypeError, KeyError, ValueError): tpw = pwd.getpwuid(run_uid) fut_owner = tpw.pw_name fut_uid = tpw.pw_uid else: try: fut_owner = run_owner except Exception: pass fut_uid = run_uid fut_group = fut_gid = None if self.file_args['group']: try:
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
tgr = grp.getgrnam(self.file_args['group']) except (ValueError, KeyError): try: tgr = grp.getgrgid(int(self.file_args['group'])) except (KeyError, ValueError, OverflowError): tgr = grp.getgrgid(run_gid) fut_group = tgr.gr_name fut_gid = tgr.gr_gid else: try: fut_group = run_group except Exception: pass fut_gid = run_gid for line in old_out.splitlines(): change = False pcs = line.split(None, 7) if len(pcs) != 8: continue if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue if len(pcs[6]) != 15: continue
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
if pcs[0][0] not in 'dl-?' or not frozenset(pcs[0][1:]).issubset('rwxstah-'): continue ztype = pcs[0][0] permstr = pcs[0][1:] version = pcs[1] ostype = pcs[2] size = int(pcs[3]) path = to_text(pcs[7], errors='surrogate_or_strict') if path in self.excludes: out += 'Path %s is excluded on request\n' % path continue if path[-1] == '/': if ztype != 'd': err += 'Path %s incorrectly tagged as "%s", but is a directory.\n' % (path, ztype) ftype = 'd' elif ztype == 'l': ftype = 'L' elif ztype == '-': ftype = 'f' elif ztype == '?': ftype = 'f'
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
if len(permstr) == 6: if path[-1] == '/': permstr = 'rwxrwxrwx' elif permstr == 'rwx---': permstr = 'rwxrwxrwx' else: permstr = 'rw-rw-rw-' file_umask = umask elif 'bsd' in systemtype.lower(): file_umask = umask else: file_umask = 0 if len(permstr) != 9 or not ZIP_FILE_MODE_RE.match(permstr): raise UnarchiveError('ZIP info perm format incorrect, %s' % permstr) b_dest = os.path.join(self.b_dest, to_bytes(path, errors='surrogate_or_strict')) try: st = os.lstat(b_dest) except Exception: change = True self.includes.append(path) err += 'Path %s is missing\n' % path diff += '>%s++++++.?? %s\n' % (ftype, path) continue if ftype == 'd' and not stat.S_ISDIR(st.st_mode): change = True self.includes.append(path)
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
err += 'File %s already exists, but not as a directory\n' % path diff += 'c%s++++++.?? %s\n' % (ftype, path) continue if ftype == 'f' and not stat.S_ISREG(st.st_mode): change = True unarchived = False self.includes.append(path) err += 'Directory %s already exists, but not as a regular file\n' % path diff += 'c%s++++++.?? %s\n' % (ftype, path) continue if ftype == 'L' and not stat.S_ISLNK(st.st_mode): change = True self.includes.append(path) err += 'Directory %s already exists, but not as a symlink\n' % path diff += 'c%s++++++.?? %s\n' % (ftype, path) continue itemized = list('.%s.......??' % ftype) dt_object = datetime.datetime(*(time.strptime(pcs[6], '%Y%m%d.%H%M%S')[0:6])) timestamp = time.mktime(dt_object.timetuple()) if stat.S_ISREG(st.st_mode): if self.module.params['keep_newer']: if timestamp > st.st_mtime: change = True self.includes.append(path) err += 'File %s is older, replacing file\n' % path itemized[4] = 't'
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
elif stat.S_ISREG(st.st_mode) and timestamp < st.st_mtime: out += 'File %s is newer, excluding file\n' % path self.excludes.append(path) continue else: if timestamp != st.st_mtime: change = True self.includes.append(path) err += 'File %s differs in mtime (%f vs %f)\n' % (path, timestamp, st.st_mtime) itemized[4] = 't' if stat.S_ISREG(st.st_mode) and size != st.st_size: change = True err += 'File %s differs in size (%d vs %d)\n' % (path, size, st.st_size) itemized[3] = 's' if stat.S_ISREG(st.st_mode): crc = crc32(b_dest, self.io_buffer_size) if crc != self._crc32(path): change = True err += 'File %s differs in CRC32 checksum (0x%08x vs 0x%08x)\n' % (path, self._crc32(path), crc) itemized[2] = 'c' if ftype != 'L': if self.file_args['mode']: if isinstance(self.file_args['mode'], int): mode = self.file_args['mode']
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
else: try: mode = int(self.file_args['mode'], 8) except Exception as e: try: mode = AnsibleModule._symbolic_mode_to_octal(st, self.file_args['mode']) except ValueError as e: self.module.fail_json(path=path, msg="%s" % to_native(e), exception=traceback.format_exc()) elif ztype == '?': mode = self._permstr_to_octal(permstr, 0) else: mode = self._permstr_to_octal(permstr, file_umask) if mode != stat.S_IMODE(st.st_mode): change = True itemized[5] = 'p' err += 'Path %s differs in permissions (%o vs %o)\n' % (path, mode, stat.S_IMODE(st.st_mode)) owner = uid = None try: owner = pwd.getpwuid(st.st_uid).pw_name except (TypeError, KeyError): uid = st.st_uid if run_uid != 0 and (fut_owner != run_owner or fut_uid != run_uid): raise UnarchiveError('Cannot change ownership of %s to %s, as user %s' % (path, fut_owner, run_owner)) if owner and owner != fut_owner: change = True err += 'Path %s is owned by user %s, not by user %s as expected\n' % (path, owner, fut_owner) itemized[6] = 'o'
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
elif uid and uid != fut_uid: change = True err += 'Path %s is owned by uid %s, not by uid %s as expected\n' % (path, uid, fut_uid) itemized[6] = 'o' group = gid = None try: group = grp.getgrgid(st.st_gid).gr_name except (KeyError, ValueError, OverflowError): gid = st.st_gid if run_uid != 0 and (fut_group != run_group or fut_gid != run_gid) and fut_gid not in groups: raise UnarchiveError('Cannot change group ownership of %s to %s, as user %s' % (path, fut_group, run_owner)) if group and group != fut_group: change = True err += 'Path %s is owned by group %s, not by group %s as expected\n' % (path, group, fut_group) itemized[6] = 'g' elif gid and gid != fut_gid: change = True err += 'Path %s is owned by gid %s, not by gid %s as expected\n' % (path, gid, fut_gid) itemized[6] = 'g' if change: if path not in self.includes: self.includes.append(path) diff += '%s %s\n' % (''.join(itemized), path) if self.includes: unarchived = False return dict(unarchived=unarchived, rc=rc, out=out, err=err, cmd=cmd, diff=diff) def unarchive(self):
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
cmd = [self.cmd_path, '-o'] if self.opts: cmd.extend(self.opts) cmd.append(self.src) if self.excludes: cmd.extend(['-x'] + self.excludes) if self.include_files: cmd.extend(self.include_files) cmd.extend(['-d', self.b_dest]) rc, out, err = self.module.run_command(cmd) return dict(cmd=cmd, rc=rc, out=out, err=err) def can_handle_archive(self):
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
missing = [] for b in self.binaries: try: setattr(self, b[1], get_bin_path(b[0])) except ValueError: missing.append(b[0]) if missing: return False, "Unable to find required '{missing}' binary in the path.".format(missing="' or '".join(missing)) cmd = [self.cmd_path, '-l', self.src] rc, out, err = self.module.run_command(cmd) if rc == 0: return True, None self.module.debug(err) return False, 'Command "%s" could not handle archive: %s' % (self.cmd_path, err) class TgzArchive(object):
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
def __init__(self, src, b_dest, file_args, module): self.src = src self.b_dest = b_dest self.file_args = file_args self.opts = module.params['extra_opts'] self.module = module if self.module.check_mode: self.module.exit_json(skipped=True, msg="remote module (%s) does not support check mode when using gtar" % self.module._name) self.excludes = [path.rstrip('/') for path in self.module.params['exclude']] self.include_files = self.module.params['include'] self.cmd_path = None self.tar_type = None self.zipflag = '-z' self._files_in_archive = [] def _get_tar_type(self): cmd = [self.cmd_path, '--version'] (rc, out, err) = self.module.run_command(cmd) tar_type = None if out.startswith('bsdtar'): tar_type = 'bsd' elif out.startswith('tar') and 'GNU' in out: tar_type = 'gnu' return tar_type @property def files_in_archive(self):
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
if self._files_in_archive: return self._files_in_archive cmd = [self.cmd_path, '--list', '-C', self.b_dest] if self.zipflag: cmd.append(self.zipflag) if self.opts: cmd.extend(['--show-transformed-names'] + self.opts) if self.excludes: cmd.extend(['--exclude=' + f for f in self.excludes]) cmd.extend(['-f', self.src]) if self.include_files: cmd.extend(self.include_files) locale = get_best_parsable_locale(self.module) rc, out, err = self.module.run_command(cmd, cwd=self.b_dest, environ_update=dict(LANG=locale, LC_ALL=locale, LC_MESSAGES=locale, LANGUAGE=locale)) if rc != 0: self.module.debug(err) raise UnarchiveError('Unable to list files in the archive: %s' % err) for filename in out.splitlines(): filename = to_native(codecs.escape_decode(filename)[0]) if filename.startswith('/'): filename = filename[1:] exclude_flag = False if self.excludes: for exclude in self.excludes:
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
if fnmatch.fnmatch(filename, exclude): exclude_flag = True break if not exclude_flag: self._files_in_archive.append(to_native(filename)) return self._files_in_archive def is_unarchived(self): cmd = [self.cmd_path, '--diff', '-C', self.b_dest] if self.zipflag: cmd.append(self.zipflag) if self.opts: cmd.extend(['--show-transformed-names'] + self.opts) if self.file_args['owner']: cmd.append('--owner=' + quote(self.file_args['owner'])) if self.file_args['group']: cmd.append('--group=' + quote(self.file_args['group'])) if self.module.params['keep_newer']: cmd.append('--keep-newer-files') if self.excludes: cmd.extend(['--exclude=' + f for f in self.excludes]) cmd.extend(['-f', self.src]) if self.include_files: cmd.extend(self.include_files) locale = get_best_parsable_locale(self.module) rc, out, err = self.module.run_command(cmd, cwd=self.b_dest, environ_update=dict(LANG=locale, LC_ALL=locale, LC_MESSAGES=locale, LANGUAGE=locale)) unarchived = True old_out = out
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
out = '' run_uid = os.getuid() for line in old_out.splitlines() + err.splitlines(): if EMPTY_FILE_RE.search(line): continue if run_uid == 0 and not self.file_args['owner'] and OWNER_DIFF_RE.search(line): out += line + '\n' if run_uid == 0 and not self.file_args['group'] and GROUP_DIFF_RE.search(line): out += line + '\n' if not self.file_args['mode'] and MODE_DIFF_RE.search(line): out += line + '\n' if MOD_TIME_DIFF_RE.search(line): out += line + '\n' if MISSING_FILE_RE.search(line): out += line + '\n' if INVALID_OWNER_RE.search(line): out += line + '\n' if INVALID_GROUP_RE.search(line): out += line + '\n' if SYMLINK_DIFF_RE.search(line): out += line + '\n' if out: unarchived = False return dict(unarchived=unarchived, rc=rc, out=out, err=err, cmd=cmd) def unarchive(self):
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
cmd = [self.cmd_path, '--extract', '-C', self.b_dest] if self.zipflag: cmd.append(self.zipflag) if self.opts: cmd.extend(['--show-transformed-names'] + self.opts) if self.file_args['owner']: cmd.append('--owner=' + quote(self.file_args['owner'])) if self.file_args['group']: cmd.append('--group=' + quote(self.file_args['group'])) if self.module.params['keep_newer']: cmd.append('--keep-newer-files') if self.excludes: cmd.extend(['--exclude=' + f for f in self.excludes]) cmd.extend(['-f', self.src]) if self.include_files: cmd.extend(self.include_files) locale = get_best_parsable_locale(self.module) rc, out, err = self.module.run_command(cmd, cwd=self.b_dest, environ_update=dict(LANG=locale, LC_ALL=locale, LC_MESSAGES=locale, LANGUAGE=locale)) return dict(cmd=cmd, rc=rc, out=out, err=err) def can_handle_archive(self):
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
try: self.cmd_path = get_bin_path('gtar') except ValueError: try: self.cmd_path = get_bin_path('tar') except ValueError: return False, "Unable to find required 'gtar' or 'tar' binary in the path" self.tar_type = self._get_tar_type() if self.tar_type != 'gnu': return False, 'Command "%s" detected as tar type %s. GNU tar required.' % (self.cmd_path, self.tar_type) try: if self.files_in_archive: return True, None except UnarchiveError as e: return False, 'Command "%s" could not handle archive: %s' % (self.cmd_path, to_native(e)) return False, 'Command "%s" found no files in archive. Empty archive files are not supported.' % self.cmd_path class TarArchive(TgzArchive):
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
def __init__(self, src, b_dest, file_args, module): super(TarArchive, self).__init__(src, b_dest, file_args, module) self.zipflag = '' class TarBzipArchive(TgzArchive): def __init__(self, src, b_dest, file_args, module): super(TarBzipArchive, self).__init__(src, b_dest, file_args, module) self.zipflag = '-j' class TarXzArchive(TgzArchive): def __init__(self, src, b_dest, file_args, module): super(TarXzArchive, self).__init__(src, b_dest, file_args, module) self.zipflag = '-J' class TarZstdArchive(TgzArchive):
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
def __init__(self, src, b_dest, file_args, module): super(TarZstdArchive, self).__init__(src, b_dest, file_args, module) # self.zipflag = '--use-compress-program=zstd' class ZipZArchive(ZipArchive): def __init__(self, src, b_dest, file_args, module): super(ZipZArchive, self).__init__(src, b_dest, file_args, module) self.zipinfoflag = '-Z' self.binaries = ( ('unzip', 'cmd_path'), ('unzip', 'zipinfo_cmd_path'), ) def can_handle_archive(self): unzip_available, error_msg = super(ZipZArchive, self).can_handle_archive() if not unzip_available: return unzip_available, error_msg cmd = [self.zipinfo_cmd_path, self.zipinfoflag] rc, out, err = self.module.run_command(cmd) if 'zipinfo' in out.lower(): return True, None return False, 'Command "unzip -Z" could not handle archive: %s' % err def pick_handler(src, dest, file_args, module):
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
handlers = [ZipArchive, ZipZArchive, TgzArchive, TarArchive, TarBzipArchive, TarXzArchive, TarZstdArchive] reasons = set() for handler in handlers: obj = handler(src, dest, file_args, module) (can_handle, reason) = obj.can_handle_archive() if can_handle: return obj reasons.add(reason) reason_msg = '\n'.join(reasons) module.fail_json(msg='Failed to find handler for "%s". Make sure the required command to extract the file is installed.\n%s' % (src, reason_msg)) def main(): module = AnsibleModule( argument_spec=dict( src=dict(type='path', required=True), dest=dict(type='path', required=True), remote_src=dict(type='bool', default=False), creates=dict(type='path'), list_files=dict(type='bool', default=False), keep_newer=dict(type='bool', default=False), exclude=dict(type='list', elements='str', default=[]), include=dict(type='list', elements='str', default=[]), extra_opts=dict(type='list', elements='str', default=[]), validate_certs=dict(type='bool', default=True), io_buffer_size=dict(type='int', default=64 * 1024),
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
copy=dict(type='bool', default=True), decrypt=dict(type='bool', default=True), ), add_file_common_args=True, supports_check_mode=True, mutually_exclusive=[('include', 'exclude')], ) src = module.params['src'] dest = module.params['dest'] abs_dest = os.path.abspath(dest) b_dest = to_bytes(abs_dest, errors='surrogate_or_strict') if not os.path.isabs(dest): module.warn("Relative destination path '{dest}' was resolved to absolute path '{abs_dest}'.".format(dest=dest, abs_dest=abs_dest)) remote_src = module.params['remote_src'] file_args = module.load_file_common_arguments(module.params) if not os.path.exists(src): if not remote_src: module.fail_json(msg="Source '%s' failed to transfer" % src) elif '://' in src: src = fetch_file(module, src) else: module.fail_json(msg="Source '%s' does not exist" % src) if not os.access(src, os.R_OK): module.fail_json(msg="Source '%s' not readable" % src) src = os.path.abspath(src)
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
try: if os.path.getsize(src) == 0: module.fail_json(msg="Invalid archive '%s', the file is 0 bytes" % src) except Exception as e: module.fail_json(msg="Source '%s' not readable, %s" % (src, to_native(e))) if not os.path.isdir(b_dest): module.fail_json(msg="Destination '%s' is not a directory" % dest) handler = pick_handler(src, b_dest, file_args, module) res_args = dict(handler=handler.__class__.__name__, dest=dest, src=src) check_results = handler.is_unarchived() if module.check_mode: res_args['changed'] = not check_results['unarchived'] elif check_results['unarchived']: res_args['changed'] = False else: try: res_args['extract_results'] = handler.unarchive() if res_args['extract_results']['rc'] != 0: module.fail_json(msg="failed to unpack %s to %s" % (src, dest), **res_args) except IOError: module.fail_json(msg="failed to unpack %s to %s" % (src, dest), **res_args) else: res_args['changed'] = True if check_results.get('diff', False):
closed
ansible/ansible
https://github.com/ansible/ansible
81,699
unarchive skipping valid archives due to pcs check
### Summary The unarchive is skipping valid archives due to the pcs check found [here](https://github.com/ansible/ansible/blob/6f65397871d089681fec5380b9ac17b62fb4e8e1/lib/ansible/modules/unarchive.py#L502C1-L504C25): ``` # Check first and seventh field in order to skip header/footer if len(pcs[0]) != 7 and len(pcs[0]) != 10: continue ``` The zipinfo output of the zip in use by this playbook: ``` zipinfo -T -s /tmp/t/1.zip Archive: /tmp/t/1.zip Archive size: 14848 bytes; Members: 4 -rw-a--- 2.0 fat 2538 t- defN 20230913.162426 deployment/scripts/setup.sh -rw-a--- 2.0 fat 743 t- defN 20230522.135636 1.ansible.vault -rw-a--- 2.0 fat 873 t- defN 20230911.104146 2.ansible.vault -rw-a--- 2.0 fat 12816 b- stor 20230913.162542 scripts.zip Members: 4; Bytes uncompressed: 16970, compressed: 14362, 15.4% Directories: 0, Files: 4, Links: 0 ``` Notice the first field (pcs[0]) is 8 characters (not 7 or 10 as expected). This zip extracts just fine using unzip. ### Issue Type Bug Report ### Component Name unarchive ### Ansible Version ```console $ ansible --version ansible [core 2.13.3] config file = /root/.ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /bin/ansible python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] jinja version = 3.1.2 libyaml = True ``` ### Configuration ```console # if using a version older than ansible-core 2.12 you should omit the '-t all' $ ansible-config dump --only-changed -t all CACHE_PLUGIN(/root/.ansible.cfg) = jsonfile CACHE_PLUGIN_CONNECTION(/root/.ansible.cfg) = /tmp/facts_cache CACHE_PLUGIN_TIMEOUT(/root/.ansible.cfg) = 7200 DEFAULT_FORKS(/root/.ansible.cfg) = 50 DEFAULT_GATHERING(/root/.ansible.cfg) = smart DEFAULT_REMOTE_USER(/root/.ansible.cfg) = ansible HOST_KEY_CHECKING(/root/.ansible.cfg) = False CACHE: ===== jsonfile: ________ _timeout(/root/.ansible.cfg) = 7200 _uri(/root/.ansible.cfg) = /tmp/facts_cache CONNECTION: ========== paramiko_ssh: ____________ host_key_checking(/root/.ansible.cfg) = False remote_user(/root/.ansible.cfg) = ansible ssh: ___ host_key_checking(/root/.ansible.cfg) = False pipelining(/root/.ansible.cfg) = True remote_user(/root/.ansible.cfg) = ansible ssh_args(/root/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey ``` ### OS / Environment RHEL 8 ### Steps to Reproduce <!--- Paste example playbooks or commands between quotes below --> ```yaml (paste below) - name: unarchive ansible.builtin.unarchive: src: /tmp/t/1.zip dest: /tmp/t remote_src= yes ``` ### Expected Results changed: [HOSTNAME] ### Actual Results ```console ok: [HOSTNAME] ``` ### Code of Conduct - [X] I agree to follow the Ansible Code of Conduct
https://github.com/ansible/ansible/issues/81699
https://github.com/ansible/ansible/pull/81705
ce9d268ab88eee1e69dfdd6bf853d021d2b7d13d
7dde4901d42e4c043adbd980c941b97cd3237bb6
2023-09-14T19:20:51Z
python
2023-11-22T00:48:31Z
lib/ansible/modules/unarchive.py
res_args['diff'] = {'prepared': check_results['diff']} if res_args.get('diff', True) and not module.check_mode: top_folders = [] for filename in handler.files_in_archive: file_args['path'] = os.path.join(b_dest, to_bytes(filename, errors='surrogate_or_strict')) try: res_args['changed'] = module.set_fs_attributes_if_different(file_args, res_args['changed'], expand=False) except (IOError, OSError) as e: module.fail_json(msg="Unexpected error when accessing exploded file: %s" % to_native(e), **res_args) if '/' in filename: top_folder_path = filename.split('/')[0] if top_folder_path not in top_folders: top_folders.append(top_folder_path) if top_folders: for f in top_folders: file_args['path'] = "%s/%s" % (dest, f) try: res_args['changed'] = module.set_fs_attributes_if_different(file_args, res_args['changed'], expand=False) except (IOError, OSError) as e: module.fail_json(msg="Unexpected error when accessing exploded file: %s" % to_native(e), **res_args) if module.params['list_files']: res_args['files'] = handler.files_in_archive module.exit_json(**res_args) if __name__ == '__main__': main()
closed
ansible/ansible
https://github.com/ansible/ansible
70,339
known_hosts module breaks when using @cert-authority keys
<!--- Verify first that your issue is not already reported on GitHub --> <!--- Also test if the latest release and devel branch are affected too --> <!--- Complete *all* sections as described, this form is processed automatically --> ##### SUMMARY If I attempt to add a key for `host.example.com` ansible removes my `@cert-authority *.example.com` ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME known_hosts ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible-playbook 2.9.10 config file = None configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible executable location = /usr/local/bin/ansible-playbook python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] ``` ##### CONFIGURATION Completely default ##### OS / ENVIRONMENT Docker image on amd64 running debian:buster-slim image id: 43e3995ee54a Installed via pip ##### STEPS TO REPRODUCE play.yml - hosts: localhost gather_facts: no vars: known_hosts_path: example_com_ed25519_key: > host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I tasks: - name: Create a copy of known_hosts copy: src: existing_known_hosts dest: test_known_hosts - name: add the ed25519 host key known_hosts: name: host.example.com key: "{{ example_com_ed25519_key }}" state: present path: "test_known_hosts" register: result - name: get the file content command: "cat test_known_hosts" register: known_hosts_v1 - name: assert that the key was added and ordering preserved assert: that: - 'result is changed' - 'known_hosts_v1.stdout_lines[-1].strip() == example_com_ed25519_key.strip()' - 'known_hosts_v1.stdout_lines[4].startswith("@cert-authority")' existing_known_hosts example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer @cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost Output # ansible-playbook play.yml --diff [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [localhost] ************************************************************************************************************* ... TASK [add the ed25519 host key] ********************************************************************************************** --- before: test_known_hosts +++ after: test_known_hosts @@ -1,3 +1,3 @@ example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer -@cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost +host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I changed: [localhost] TASK [get the file content] ************************************************************************************************** changed: [localhost] TASK [assert that the key was added and ordering preserved] ****************************************************************** fatal: [localhost]: FAILED! => {"msg": "The conditional check 'known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")' failed. The error was: error while evaluating conditional (known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")): list object has no element 4"} PLAY RECAP ******************************************************************************************************************* localhost : ok=3 changed=3 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> I expected adding `hosts.example.com` not to have the side effect of removing `@cert-authority *.example.com ...` ##### ACTUAL RESULTS See Above
https://github.com/ansible/ansible/issues/70339
https://github.com/ansible/ansible/pull/70340
7dde4901d42e4c043adbd980c941b97cd3237bb6
a4b00793be46f703e32ee4c440f303d19d2c652d
2020-06-27T04:20:12Z
python
2023-11-22T00:55:01Z
lib/ansible/modules/known_hosts.py
from __future__ import annotations DOCUMENTATION = r''' --- module: known_hosts short_description: Add or remove a host from the C(known_hosts) file description: - The M(ansible.builtin.known_hosts) module lets you add or remove a host keys from the C(known_hosts) file.
closed
ansible/ansible
https://github.com/ansible/ansible
70,339
known_hosts module breaks when using @cert-authority keys
<!--- Verify first that your issue is not already reported on GitHub --> <!--- Also test if the latest release and devel branch are affected too --> <!--- Complete *all* sections as described, this form is processed automatically --> ##### SUMMARY If I attempt to add a key for `host.example.com` ansible removes my `@cert-authority *.example.com` ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME known_hosts ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible-playbook 2.9.10 config file = None configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible executable location = /usr/local/bin/ansible-playbook python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] ``` ##### CONFIGURATION Completely default ##### OS / ENVIRONMENT Docker image on amd64 running debian:buster-slim image id: 43e3995ee54a Installed via pip ##### STEPS TO REPRODUCE play.yml - hosts: localhost gather_facts: no vars: known_hosts_path: example_com_ed25519_key: > host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I tasks: - name: Create a copy of known_hosts copy: src: existing_known_hosts dest: test_known_hosts - name: add the ed25519 host key known_hosts: name: host.example.com key: "{{ example_com_ed25519_key }}" state: present path: "test_known_hosts" register: result - name: get the file content command: "cat test_known_hosts" register: known_hosts_v1 - name: assert that the key was added and ordering preserved assert: that: - 'result is changed' - 'known_hosts_v1.stdout_lines[-1].strip() == example_com_ed25519_key.strip()' - 'known_hosts_v1.stdout_lines[4].startswith("@cert-authority")' existing_known_hosts example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer @cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost Output # ansible-playbook play.yml --diff [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [localhost] ************************************************************************************************************* ... TASK [add the ed25519 host key] ********************************************************************************************** --- before: test_known_hosts +++ after: test_known_hosts @@ -1,3 +1,3 @@ example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer -@cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost +host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I changed: [localhost] TASK [get the file content] ************************************************************************************************** changed: [localhost] TASK [assert that the key was added and ordering preserved] ****************************************************************** fatal: [localhost]: FAILED! => {"msg": "The conditional check 'known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")' failed. The error was: error while evaluating conditional (known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")): list object has no element 4"} PLAY RECAP ******************************************************************************************************************* localhost : ok=3 changed=3 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> I expected adding `hosts.example.com` not to have the side effect of removing `@cert-authority *.example.com ...` ##### ACTUAL RESULTS See Above
https://github.com/ansible/ansible/issues/70339
https://github.com/ansible/ansible/pull/70340
7dde4901d42e4c043adbd980c941b97cd3237bb6
a4b00793be46f703e32ee4c440f303d19d2c652d
2020-06-27T04:20:12Z
python
2023-11-22T00:55:01Z
lib/ansible/modules/known_hosts.py
- Starting at Ansible 2.2, multiple entries per host are allowed, but only one for each key type supported by ssh. This is useful if you're going to want to use the M(ansible.builtin.git) module over ssh, for example. - If you have a very large number of host keys to manage, you will find the M(ansible.builtin.template) module more useful. version_added: "1.9" options: name: aliases: [ 'host' ] description: - The host to add or remove (must match a host specified in key). It will be converted to lowercase so that ssh-keygen can find it. - Must match with <hostname> or <ip> present in key attribute. - For custom SSH port, O(name) needs to specify port as well. See example section. type: str required: true key: description: - The SSH public host key, as a string. - Required if O(state=present), optional when O(state=absent), in which case all keys for the host are removed. - The key must be in the right format for SSH (see sshd(8), section "SSH_KNOWN_HOSTS FILE FORMAT"). - Specifically, the key should not match the format that is found in an SSH pubkey file, but should rather have the hostname prepended to a line that includes the pubkey, the same way that it would appear in the known_hosts file. The value prepended to the line must also match the value of the name parameter. - Should be of format C(<hostname[,IP]> ssh-rsa <pubkey>). - For custom SSH port, O(key) needs to specify port as well. See example section. type: str path: description: - The known_hosts file to edit. - The known_hosts file will be created if needed. The rest of the path must exist prior to running the module. default: "~/.ssh/known_hosts" type: path
closed
ansible/ansible
https://github.com/ansible/ansible
70,339
known_hosts module breaks when using @cert-authority keys
<!--- Verify first that your issue is not already reported on GitHub --> <!--- Also test if the latest release and devel branch are affected too --> <!--- Complete *all* sections as described, this form is processed automatically --> ##### SUMMARY If I attempt to add a key for `host.example.com` ansible removes my `@cert-authority *.example.com` ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME known_hosts ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible-playbook 2.9.10 config file = None configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible executable location = /usr/local/bin/ansible-playbook python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] ``` ##### CONFIGURATION Completely default ##### OS / ENVIRONMENT Docker image on amd64 running debian:buster-slim image id: 43e3995ee54a Installed via pip ##### STEPS TO REPRODUCE play.yml - hosts: localhost gather_facts: no vars: known_hosts_path: example_com_ed25519_key: > host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I tasks: - name: Create a copy of known_hosts copy: src: existing_known_hosts dest: test_known_hosts - name: add the ed25519 host key known_hosts: name: host.example.com key: "{{ example_com_ed25519_key }}" state: present path: "test_known_hosts" register: result - name: get the file content command: "cat test_known_hosts" register: known_hosts_v1 - name: assert that the key was added and ordering preserved assert: that: - 'result is changed' - 'known_hosts_v1.stdout_lines[-1].strip() == example_com_ed25519_key.strip()' - 'known_hosts_v1.stdout_lines[4].startswith("@cert-authority")' existing_known_hosts example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer @cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost Output # ansible-playbook play.yml --diff [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [localhost] ************************************************************************************************************* ... TASK [add the ed25519 host key] ********************************************************************************************** --- before: test_known_hosts +++ after: test_known_hosts @@ -1,3 +1,3 @@ example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer -@cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost +host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I changed: [localhost] TASK [get the file content] ************************************************************************************************** changed: [localhost] TASK [assert that the key was added and ordering preserved] ****************************************************************** fatal: [localhost]: FAILED! => {"msg": "The conditional check 'known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")' failed. The error was: error while evaluating conditional (known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")): list object has no element 4"} PLAY RECAP ******************************************************************************************************************* localhost : ok=3 changed=3 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> I expected adding `hosts.example.com` not to have the side effect of removing `@cert-authority *.example.com ...` ##### ACTUAL RESULTS See Above
https://github.com/ansible/ansible/issues/70339
https://github.com/ansible/ansible/pull/70340
7dde4901d42e4c043adbd980c941b97cd3237bb6
a4b00793be46f703e32ee4c440f303d19d2c652d
2020-06-27T04:20:12Z
python
2023-11-22T00:55:01Z
lib/ansible/modules/known_hosts.py
hash_host: description: - Hash the hostname in the known_hosts file. type: bool default: "no" version_added: "2.3" state: description: - V(present) to add the host key. - V(absent) to remove it. choices: [ "absent", "present" ] default: "present" type: str attributes: check_mode: support: full diff_mode: support: full platform: platforms: posix extends_documentation_fragment: - action_common_attributes author: - Matthew Vernon (@mcv21) ''' EXAMPLES = r''' - name: Tell the host about our servers it might want to ssh to ansible.builtin.known_hosts: path: /etc/ssh/ssh_known_hosts name: foo.com.invalid
closed
ansible/ansible
https://github.com/ansible/ansible
70,339
known_hosts module breaks when using @cert-authority keys
<!--- Verify first that your issue is not already reported on GitHub --> <!--- Also test if the latest release and devel branch are affected too --> <!--- Complete *all* sections as described, this form is processed automatically --> ##### SUMMARY If I attempt to add a key for `host.example.com` ansible removes my `@cert-authority *.example.com` ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME known_hosts ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible-playbook 2.9.10 config file = None configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible executable location = /usr/local/bin/ansible-playbook python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] ``` ##### CONFIGURATION Completely default ##### OS / ENVIRONMENT Docker image on amd64 running debian:buster-slim image id: 43e3995ee54a Installed via pip ##### STEPS TO REPRODUCE play.yml - hosts: localhost gather_facts: no vars: known_hosts_path: example_com_ed25519_key: > host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I tasks: - name: Create a copy of known_hosts copy: src: existing_known_hosts dest: test_known_hosts - name: add the ed25519 host key known_hosts: name: host.example.com key: "{{ example_com_ed25519_key }}" state: present path: "test_known_hosts" register: result - name: get the file content command: "cat test_known_hosts" register: known_hosts_v1 - name: assert that the key was added and ordering preserved assert: that: - 'result is changed' - 'known_hosts_v1.stdout_lines[-1].strip() == example_com_ed25519_key.strip()' - 'known_hosts_v1.stdout_lines[4].startswith("@cert-authority")' existing_known_hosts example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer @cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost Output # ansible-playbook play.yml --diff [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [localhost] ************************************************************************************************************* ... TASK [add the ed25519 host key] ********************************************************************************************** --- before: test_known_hosts +++ after: test_known_hosts @@ -1,3 +1,3 @@ example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer -@cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost +host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I changed: [localhost] TASK [get the file content] ************************************************************************************************** changed: [localhost] TASK [assert that the key was added and ordering preserved] ****************************************************************** fatal: [localhost]: FAILED! => {"msg": "The conditional check 'known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")' failed. The error was: error while evaluating conditional (known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")): list object has no element 4"} PLAY RECAP ******************************************************************************************************************* localhost : ok=3 changed=3 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> I expected adding `hosts.example.com` not to have the side effect of removing `@cert-authority *.example.com ...` ##### ACTUAL RESULTS See Above
https://github.com/ansible/ansible/issues/70339
https://github.com/ansible/ansible/pull/70340
7dde4901d42e4c043adbd980c941b97cd3237bb6
a4b00793be46f703e32ee4c440f303d19d2c652d
2020-06-27T04:20:12Z
python
2023-11-22T00:55:01Z
lib/ansible/modules/known_hosts.py
key: "{{ lookup('ansible.builtin.file', 'pubkeys/foo.com.invalid') }}" - name: Another way to call known_hosts ansible.builtin.known_hosts: name: host1.example.com # or 10.9.8.77 key: host1.example.com,10.9.8.77 ssh-rsa ASDeararAIUHI324324 # some key gibberish path: /etc/ssh/ssh_known_hosts state: present - name: Add host with custom SSH port ansible.builtin.known_hosts: name: '[host1.example.com]:2222' key: '[host1.example.com]:2222 ssh-rsa ASDeararAIUHI324324' # some key gibberish path: /etc/ssh/ssh_known_hosts state: present ''' # import base64 import errno import hashlib import hmac import os import os.path import re import tempfile from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.text.converters import to_bytes, to_native def enforce_state(module, params): """ Add or remove key. """ host = params["name"].lower()
closed
ansible/ansible
https://github.com/ansible/ansible
70,339
known_hosts module breaks when using @cert-authority keys
<!--- Verify first that your issue is not already reported on GitHub --> <!--- Also test if the latest release and devel branch are affected too --> <!--- Complete *all* sections as described, this form is processed automatically --> ##### SUMMARY If I attempt to add a key for `host.example.com` ansible removes my `@cert-authority *.example.com` ##### ISSUE TYPE - Bug Report ##### COMPONENT NAME known_hosts ##### ANSIBLE VERSION <!--- Paste verbatim output from "ansible --version" between quotes --> ```paste below ansible-playbook 2.9.10 config file = None configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible executable location = /usr/local/bin/ansible-playbook python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] ``` ##### CONFIGURATION Completely default ##### OS / ENVIRONMENT Docker image on amd64 running debian:buster-slim image id: 43e3995ee54a Installed via pip ##### STEPS TO REPRODUCE play.yml - hosts: localhost gather_facts: no vars: known_hosts_path: example_com_ed25519_key: > host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I tasks: - name: Create a copy of known_hosts copy: src: existing_known_hosts dest: test_known_hosts - name: add the ed25519 host key known_hosts: name: host.example.com key: "{{ example_com_ed25519_key }}" state: present path: "test_known_hosts" register: result - name: get the file content command: "cat test_known_hosts" register: known_hosts_v1 - name: assert that the key was added and ordering preserved assert: that: - 'result is changed' - 'known_hosts_v1.stdout_lines[-1].strip() == example_com_ed25519_key.strip()' - 'known_hosts_v1.stdout_lines[4].startswith("@cert-authority")' existing_known_hosts example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer @cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost Output # ansible-playbook play.yml --diff [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [localhost] ************************************************************************************************************* ... TASK [add the ed25519 host key] ********************************************************************************************** --- before: test_known_hosts +++ after: test_known_hosts @@ -1,3 +1,3 @@ example.com ssh-dss AAAAB3NzaC1kc3MAAACBALT8YHxZ59d8yX4oQNPbpdK9AMPRQGKFY9X13S2fp4UMPijiB3ETxU1bAyVTjTbsoag065naFt13aIVl+u0MDPfMuYgVJFEorAZkDlBixvT25zpKyQhI4CtHhZ9Y9YWug4xLqSaFUYEPO31Bie7k8xRfDwsHtzTRPp/0zRURwARHAAAAFQDLx2DZMm3cR8cZtbq4zdSvkXLh0wAAAIAalkQYziu2b5dDRQMiFpDLpPdbymyVhDMmRKnXwAB1+dhGyJLGvfe0xO+ibqGXMp1aZ1iC3a/vHTpYKDVqKIIpFg5r0fxAcAZkJR0aRC8RDxW/IclbIliETD71osIT8I47OFc7vAVCWP8JbV3ZYzR+i98WUkmZ4/ZUzsDl2gi7WAAAAIAsdTGwAo4Fs784TdP2tIHCqxAIz2k4tWmZyeRmXkH5K/P1o9XSh3RNxvFKK7BY6dQK+h9jLunMBs0SCzhMoTcXaJq331kmLJltjq5peo0PnLGnQz5pas0PD7p7gb+soklmHoVp7J2oMC/U4N1Rxr6g9sv8Rpsf1PTPDT3sEbze6A== root@freezer -@cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDXh1gk2xgS2MekPvo7ZEKiOT7HoyvOAzai2GqoLXGHO # example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM6OSqweGdPdQ/metQaf738AdN3P+itYp1AypOTgXkyj root@localhost +host.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFp8VtD59XAcxkj1qbfCtB1in9nm5WiipORjtVJUBA6I changed: [localhost] TASK [get the file content] ************************************************************************************************** changed: [localhost] TASK [assert that the key was added and ordering preserved] ****************************************************************** fatal: [localhost]: FAILED! => {"msg": "The conditional check 'known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")' failed. The error was: error while evaluating conditional (known_hosts_v1.stdout_lines[4].startswith(\"@cert-authority\")): list object has no element 4"} PLAY RECAP ******************************************************************************************************************* localhost : ok=3 changed=3 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 ##### EXPECTED RESULTS <!--- Describe what you expected to happen when running the steps above --> I expected adding `hosts.example.com` not to have the side effect of removing `@cert-authority *.example.com ...` ##### ACTUAL RESULTS See Above
https://github.com/ansible/ansible/issues/70339
https://github.com/ansible/ansible/pull/70340
7dde4901d42e4c043adbd980c941b97cd3237bb6
a4b00793be46f703e32ee4c440f303d19d2c652d
2020-06-27T04:20:12Z
python
2023-11-22T00:55:01Z
lib/ansible/modules/known_hosts.py
key = params.get("key", None) path = params.get("path") hash_host = params.get("hash_host") state = params.get("state") sshkeygen = module.get_bin_path("ssh-keygen", True) if not key and state != "absent": module.fail_json(msg="No key specified when adding a host") if key and hash_host: key = hash_host_key(host, key) if key and not key.endswith('\n'): key += '\n' sanity_check(module, host, key, sshkeygen) found, replace_or_add, found_line = search_for_host_key(module, host, key, path, sshkeygen) params['diff'] = compute_diff(path, found_line, replace_or_add, state, key) if state == 'absent' and not found_line and key: params['changed'] = False return params if module.check_mode: module.exit_json(changed=replace_or_add or (state == "present") != found, diff=params['diff'])