Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module_defaults for yum do not get picked up when invoked via package #72918

Closed
johnbui423 opened this issue Dec 9, 2020 · 1 comment · Fixed by #73864
Closed

module_defaults for yum do not get picked up when invoked via package #72918

johnbui423 opened this issue Dec 9, 2020 · 1 comment · Fixed by #73864
Labels
affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. P3 Priority 3 - Approved, No Time Limitation support:community This issue/PR relates to code supported by the Ansible community.

Comments

@johnbui423
Copy link
Contributor

johnbui423 commented Dec 9, 2020

SUMMARY

In 2.10.x, module_defaults for yum do not get picked up when invoked via package. It works fine with 2.9.x.

This seems to be a regression of #57482 - basing this bug report largely on that original issue.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

module_defaults

ANSIBLE VERSION
ansible 2.10.3
OS / ENVIRONMENT

CentOS 7

STEPS TO REPRODUCE
---

- hosts: localhost
  module_defaults:
    yum:
      lock_timeout: 120
  tasks:
    - package:
        name: yum
        state: present
    - yum:
        name: yum
        state: present
EXPECTED RESULTS

lock_timeout is set to 120 for both tasks

ACTUAL RESULTS
[...]
TASK [package]
[...]
            "lock_timeout": 30, 
[...]
}

TASK [yum] 
[...]
            "lock_timeout": 120,
[...]
@sivel
Copy link
Member

sivel commented Dec 9, 2020

The problem lies here:

# get defaults for specific module
new_module_args = get_action_args_with_defaults(
module, new_module_args, self._task.module_defaults, self._templar, self._task._ansible_internal_redirect_list
)

self._task._ansible_internal_redirect_list only references ['package'], so the defaults are never applied.

We may have to extract this logic into some form of helper so that we can use it to build a list based on the selected action/module:

# If the plugin is resolved and redirected smuggle the list of candidate names via the task attribute 'internal_redirect_list'
context = action_loader.find_plugin_with_context(item, collection_list=self._collection_list)
if not context.resolved:
context = module_loader.find_plugin_with_context(item, collection_list=self._collection_list)
if context.resolved and context.redirect_list:
self.internal_redirect_list = context.redirect_list
elif context.redirect_list:
self.internal_redirect_list = context.redirect_list

I'm not sure that we can just pass [module] instead of an actual internal redirect list.

This issue will likely affect:

  • lib/ansible/plugins/action/package.py
  • lib/ansible/plugins/action/service.py
  • lib/ansible/plugins/action/gather_facts.py

@ansibot ansibot added affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. labels Dec 9, 2020
@Shrews Shrews added P3 Priority 3 - Approved, No Time Limitation and removed needs_triage Needs a first human triage before being processed. labels Dec 10, 2020
s-hertel added a commit that referenced this issue May 27, 2021
…#73864)

* Fix module-specific defaults in the gather_facts, package, and service action plugins.

* Handle ansible.legacy actions better in get_action_args_with_defaults

* Add tests for each action plugin

* Changelog

Fixes #72918
s-hertel added a commit to s-hertel/ansible that referenced this issue May 27, 2021
…ansible#73864)

* Fix module-specific defaults in the gather_facts, package, and service action plugins.

* Handle ansible.legacy actions better in get_action_args_with_defaults

* Add tests for each action plugin

* Changelog

Fixes ansible#72918

(cherry picked from commit 5640093)
s-hertel added a commit to s-hertel/ansible that referenced this issue May 27, 2021
…ansible#73864)

* Fix module-specific defaults in the gather_facts, package, and service action plugins.

* Handle ansible.legacy actions better in get_action_args_with_defaults

* Add tests for each action plugin

* Changelog

Fixes ansible#72918

(cherry picked from commit 5640093)
relrod pushed a commit that referenced this issue Jun 14, 2021
…74850)

* Use the module redirect_list when getting defaults for action plugins (#73864)

* Fix module-specific defaults in the gather_facts, package, and service action plugins.

* Handle ansible.legacy actions better in get_action_args_with_defaults

* Add tests for each action plugin

* Changelog

Fixes #72918

(cherry picked from commit 5640093)

* Fix tests for < 3.8

(cherry picked from commit 267b721)
relrod pushed a commit that referenced this issue Jun 14, 2021
…74849)

* Use the module redirect_list when getting defaults for action plugins (#73864)

* Fix module-specific defaults in the gather_facts, package, and service action plugins.

* Handle ansible.legacy actions better in get_action_args_with_defaults

* Add tests for each action plugin

* Changelog

Fixes #72918

(cherry picked from commit 5640093)

* Fix tests for < 3.8
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jun 23, 2021
v2.10.11
========

Security Fixes
--------------
- templating engine fix for not preserving usnafe status when trying to preserve newlines. CVE-2021-3583

Bugfixes
--------
- gather_facts, package, service - fix using module_defaults for the modules in addition to the action plugins. (ansible/ansible#72918)
- psrp - Always cleanup the last run pipeline if a second pipeline is invoked to avoid violating any resource limits.
- psrp - Fix error when resetting a connection that was initialised but not connected - (ansible/ansible#74092).
- psrp - Try to clean up any server-side resources when resetting a connection.
@ansible ansible locked and limited conversation to collaborators Jun 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.10 This issue/PR affects Ansible v2.10 bug This issue/PR relates to a bug. P3 Priority 3 - Approved, No Time Limitation support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants