Skip to content

Conversation

@barpavel
Copy link

@barpavel barpavel commented Nov 26, 2025

SUMMARY

Fixes deprecated ansible.module_utils imports that will be removed in ansible-core 2.24.

This PR addresses deprecation warnings reported in #686 by updating import statements in the plugins/action/synchronize.py action plugin, plugins/modules/synchronize.py module, and plugins/modules/mount.py module to use the new recommended import paths.

Deprecated imports replaced:

plugins/action/synchronize.py:

  • ansible.module_utils._textansible.module_utils.common.text.converters
  • ansible.module_utils.common._collections_compatcollections.abc
  • ansible.module_utils.six → Python 3 standard library (CI compliance)

plugins/modules/synchronize.py:

  • ansible.module_utils._textansible.module_utils.common.text.converters
  • ansible.module_utils.six → Python 3 standard library (CI compliance)

plugins/modules/mount.py:

  • ansible.module_utils._textansible.module_utils.common.text.converters
  • ansible.module_utils.six → Python 3 standard library (CI compliance)

Fixes #686

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

plugins/action/synchronize.py, plugins/modules/synchronize.py, plugins/modules/mount.py

ADDITIONAL INFORMATION

Testing performed:

  • Built and installed the collection locally with the fixes
  • Tested with ansible-core 2.18.12 and Python 3
  • Verified all deprecation warnings are resolved for all modules
  • Confirmed synchronize and mount modules function correctly with no regressions

Before (with deprecation warnings):
[DEPRECATION WARNING]: Importing to_text from ansible.module_utils._text is deprecated.
This feature will be removed from ansible-core version 2.24.
Use ansible.module_utils.common.text.converters instead.

[DEPRECATION WARNING]: The ansible.module_utils.common._collections_compat module is deprecated.
This feature will be removed from ansible-core version 2.24.
Use collections.abc from the Python standard library instead.

After (with fixes applied):
[No deprecation warnings]
Build completed successfully with no ansible.module_utils deprecation warnings.

@softwarefactory-project-zuul
Copy link
Contributor

@barpavel barpavel force-pushed the fix-686-module-utils-deprecation branch 4 times, most recently from 640bd9d to e9e6079 Compare November 27, 2025 00:46
@softwarefactory-project-zuul
Copy link
Contributor

@barpavel barpavel force-pushed the fix-686-module-utils-deprecation branch 2 times, most recently from db3dc32 to 3fb8408 Compare November 27, 2025 01:09
@softwarefactory-project-zuul
Copy link
Contributor

@barpavel
Copy link
Author

The remaining CI failures are pre-existing issues in files not modified by this PR (all showing 0% in the error messages). The files I modified (synchronize.py and mount.py) pass all sanity checks.

Remaining errors (all pre-existing):

  • plugins/callback/cgroup_perf_recap.py:145:0 (0%)
  • plugins/modules/sysctl.py:113:0 (0%)
  • plugins/shell/csh.py:16:0 (0%)
  • plugins/shell/fish.py:16:0 (0%)
  • tests/unit/mock/procenv.py:29:0 (0%)
  • tests/unit/mock/yaml_helper.py:8:0 (0%)
  • tests/unit/modules/conftest.py:12:0 (0%)
  • tests/utils/shippable/timing.py:1:1 (0%)

The 0% indicates these files were not touched by this PR. All files modified by this PR pass their respective sanity checks.

@barpavel barpavel force-pushed the fix-686-module-utils-deprecation branch from 3fb8408 to c19d766 Compare November 28, 2025 14:48
@softwarefactory-project-zuul
Copy link
Contributor

@sthen
Copy link

sthen commented Dec 20, 2025

also needs conversions for to_bytes, to_native and shlex_quote in plugins/modules/synchronize.py, I think?

bob-beck pushed a commit to openbsd/ports that referenced this pull request Dec 20, 2025
@barpavel barpavel marked this pull request as draft December 23, 2025 15:57
@barpavel barpavel force-pushed the fix-686-module-utils-deprecation branch from c19d766 to 0f0cb76 Compare December 23, 2025 16:03
@softwarefactory-project-zuul
Copy link
Contributor

@barpavel barpavel force-pushed the fix-686-module-utils-deprecation branch 2 times, most recently from ffabe10 to 4a7182b Compare December 23, 2025 20:54
@softwarefactory-project-zuul
Copy link
Contributor

@barpavel barpavel force-pushed the fix-686-module-utils-deprecation branch 2 times, most recently from 3de63b8 to 9fea277 Compare December 23, 2025 21:13
@softwarefactory-project-zuul
Copy link
Contributor

@barpavel barpavel force-pushed the fix-686-module-utils-deprecation branch from 9fea277 to 11901c0 Compare December 23, 2025 21:53
@softwarefactory-project-zuul
Copy link
Contributor

Replace deprecated module_utils imports:
- ansible.module_utils._text -> ansible.module_utils.common.text.converters
- ansible.module_utils.common._collections_compat -> collections.abc

Fixes ansible-collections#686
Replace deprecated module_utils import:
- ansible.module_utils._text -> ansible.module_utils.common.text.converters

Fixes ansible-collections#686
Replace deprecated module_utils imports:
- ansible.module_utils._text -> ansible.module_utils.common.text.converters

Fixes ansible-collections#686
@barpavel barpavel force-pushed the fix-686-module-utils-deprecation branch 2 times, most recently from 5838c37 to 93cd49a Compare December 23, 2025 23:48
@softwarefactory-project-zuul
Copy link
Contributor

Replace deprecated ansible.module_utils.six imports with Python 3
standard library equivalents to pass pylint sanity checks.

plugins/action/synchronize.py:
- ansible.module_utils.six.string_types → str
- ansible.module_utils.six.moves.shlex_quote → shlex.quote

plugins/modules/synchronize.py:
- ansible.module_utils.six.moves.shlex_quote → shlex.quote

plugins/modules/mount.py:
- ansible.module_utils.six.iteritems → dict.items()
Added changelog entry documenting the bugfixes for synchronize
and mount modules' deprecated import issues.

Related to ansible-collections#686

Co-authored-by: Cursor AI
Signed-off-by: Pavel Bar <[email protected]>
@barpavel barpavel force-pushed the fix-686-module-utils-deprecation branch from 93cd49a to 64a81b4 Compare December 24, 2025 13:45
@softwarefactory-project-zuul
Copy link
Contributor

@barpavel barpavel marked this pull request as ready for review December 24, 2025 14:09
@barpavel
Copy link
Author

barpavel commented Dec 24, 2025

@sthen Thank you for reviewing! I've addressed your comment and added the missing conversions for to_bytes, to_native, and shlex_quote in plugins/modules/synchronize.py.

CI Status: ✅ All 56 checks passing!

Note on Python 2 compatibility: The shlex_quote replacement required special handling in plugins/modules/synchronize.py (see lines 370-376):

# TODO(Python2): shlex.quote was added in Python 3.3. This module may run on
# target hosts with Python 2.7 (e.g., older RHEL systems in CI integration tests).
# Remove the try/except fallback to pipes.quote when Python 2 support is dropped.
try:
    from shlex import quote as shlex_quote
except ImportError:
    from pipes import quote as shlex_quote

This is necessary because modules run on target hosts which may still be Python 2.7 (e.g., CentOS 7). When I initially used shlex.quote() directly, the CI failed with AttributeError: 'module' object has no attribute 'quote' on the Docker 2.16 CentOS 7 integration test (see failed build log).

Side note: It might be worth considering updating the CI test matrix to drop Python 2 targets (like CentOS 7), given that Python 2 reached end-of-life in January 2020 and ansible-core 2.12+ no longer supports Python 2 on the controller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

synchronize: deprecation warning to_text

2 participants