Fix all deprecated module_utils imports before ansible-core 2.24 removal SUMMARY Fixes all deprecated ansible.module_utils imports across the entire collection that will be removed in ansible-core 2.24. This PR comprehensively addresses deprecation warnings reported in #686 by updating import statements in 20 files to use the new recommended import paths, and removes 8 unused test utility files that contained deprecated imports. Deprecated imports replaced: Deprecated import Replacement ansible.module_utils._text ansible.module_utils.common.text.converters ansible.module_utils.common._collections_compat collections.abc ansible.module_utils.six.moves.shlex_quote shlex.quote ansible.module_utils.six.moves.reduce functools.reduce ansible.module_utils.six.moves.urllib.parse.urlparse urllib.parse.urlparse ansible.module_utils.six.string_types basestring/str (Python 2/3 compatible) ansible.module_utils.six.text_type str ansible.module_utils.six.PY3 Removed (simplified Python 2/3 conditionals) ansible.module_utils.six.with_metaclass Native metaclass= syntax ansible.module_utils.six.iteritems dict.items() Files fixed (20 files, 1 commit per file for easier review): plugins/action/patch.py plugins/action/synchronize.py plugins/callback/cgroup_perf_recap.py plugins/callback/json.py plugins/callback/jsonl.py plugins/callback/profile_roles.py plugins/callback/profile_tasks.py plugins/modules/acl.py plugins/modules/authorized_key.py plugins/modules/firewalld_info.py plugins/modules/mount.py plugins/modules/patch.py plugins/modules/rhel_rpm_ostree.py plugins/modules/rpm_ostree_upgrade.py plugins/modules/seboolean.py plugins/modules/synchronize.py plugins/modules/sysctl.py plugins/shell/csh.py plugins/shell/fish.py tests/unit/modules/system/test_mount.py Files deleted (8 unused test utility files): These files are dead code - none of them are imported or used anywhere in the test suite or the collection. Removing them also addresses Python 2.7 compatibility concerns raised in code review, as several contained deprecated imports that would be incorrect to fix for Python 2. tests/unit/compat/builtins.py tests/unit/mock/loader.py tests/unit/mock/path.py tests/unit/mock/procenv.py tests/unit/mock/vault_helper.py tests/unit/mock/yaml_helper.py tests/unit/modules/conftest.py tests/unit/modules/utils.py Completeness verified with: git grep -n -P '_compat|utils._text|utils.six' -- '*.py' | grep -v yml This command returns no results, confirming all deprecated imports have been replaced. Notes on Python 2.7 compatibility: For modules that may run on Python 2.7 managed hosts (e.g., authorized_key.py, synchronize.py, sysctl.py), Python 2/3 compatible fallbacks were used instead of direct Python 3 replacements: authorized_key.py: try/except ImportError for urllib.parse.urlparse (falls back to urlparse on Python 2) synchronize.py: try/except ImportError for shlex.quote (falls back to pipes.quote on Python 2) sysctl.py: uses sys.version_info to set string_types to str on Python 3 (basestring on Python 2) Also removes corresponding pylint:ansible-bad-import-from entries from tests/sanity/ignore-2.21.txt and tests/sanity/ignore-2.22.txt where applicable. Fixes #686 ISSUE TYPE Bugfix Pull Request ADDITIONAL INFORMATION Approach: Each file is fixed in a separate commit for easier code review. The changelog fragment is added in a final commit. Corresponding pylint:ansible-bad-import-from ignore entries in tests/sanity/ignore-2.21.txt and tests/sanity/ignore-2.22.txt are removed in the same commit as the file fix (or the file removal commit). CI results: All 59 checks passing (Azure Pipelines sanity, units, lint, Docker, Remote across ansible-core 2.17 through devel, and Zuul ansible/check). Reviewed-by: Felix Fontein <felix@fontein.de> Reviewed-by: Pavel Bar Reviewed-by: Abhijeet Kasurde
ansible.posix
Communication
- Join the Ansible forum:
- Get Help: get help or help others.
- Social Spaces: gather and interact with fellow enthusiasts.
- News & Announcements: track project-wide announcements including social events.
Description
An Ansible Collection of modules and plugins that target POSIX UNIX/Linux and derivative Operating Systems.
Requirements
- Python:
- The Python interpreter version must meet Ansible Core's requirements.
- Ansible Core:
- ansible-core 2.16 or later
Installation
Before using this collection, you need to install it with the Ansible Galaxy command-line tool:
ansible-galaxy collection install ansible.posix
You can also include it in a requirements.yml file and install it with ansible-galaxy collection install -r requirements.yml, using the format:
collections:
- name: ansible.posix
Note that if you install any collections from Ansible Galaxy, they will not be upgraded automatically when you upgrade the Ansible package. To upgrade the collection to the latest available version, run the following command:
ansible-galaxy collection install ansible.posix --upgrade
You can also install a specific version of the collection, for example, if you need to downgrade when something is broken in the latest version (please report an issue in this repository). Use the following syntax to install version 2.0.0:
ansible-galaxy collection install ansible.posix:==2.0.0
See using Ansible collections for more details.
- The Ansible Bullhorn newsletter: used to announce releases and important changes.
For more information about communication, see the Ansible communication guide.
Use Cases
You can see the general use-cases as an example by ansible-doc command like below.
For example, ansible.posix.firewalld module:
ansible-doc ansible.posix.firewalld
Also, if you want to confirm the plugins descriptions, you can follow the following option with ansible-doc command:
For example, ansible.posix.profile_tasks callback plugin:
ansible-doc -t callback ansible.posix.profile_tasks
Testing
The following ansible-core versions have been tested with this collection:
- ansible-core 2.20 (devel)
- ansible-core 2.19 (stable) *
- ansible-core 2.18 (stable)
- ansible-core 2.17 (stable)
Contributing
We welcome community contributions to this collection. For more details, see Contributing to Ansible-maintained collections for complete details.
Support
See Communication section.
Release Notes and Roadmap
See changelog for more details.
Related Information
This document was written using the following template.
The README has been carefully prepared to cover the community template, but if you find any problems, please file a documentation issue.
License Information
GNU General Public License v3.0 or later.
See COPYING to see the full text.