diff --git a/changelogs/fragments/70792-yum-action-plugin-use-as-alias-of-use-backend.yml b/changelogs/fragments/70792-yum-action-plugin-use-as-alias-of-use-backend.yml new file mode 100644 index 00000000000..6e14eb04063 --- /dev/null +++ b/changelogs/fragments/70792-yum-action-plugin-use-as-alias-of-use-backend.yml @@ -0,0 +1,2 @@ +bugfixes: + - yum - yum action plugin changes to support 'use' as an alias of 'use_backend' (https://github.com/ansible/ansible/issues/70774). diff --git a/lib/ansible/plugins/action/yum.py b/lib/ansible/plugins/action/yum.py index 9d3e1454446..d90a9e00cfc 100644 --- a/lib/ansible/plugins/action/yum.py +++ b/lib/ansible/plugins/action/yum.py @@ -17,6 +17,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +from ansible.errors import AnsibleActionFail from ansible.plugins.action import ActionBase from ansible.utils.display import Display @@ -47,7 +48,10 @@ class ActionModule(ActionBase): del tmp # tmp no longer has any effect # Carry-over concept from the package action plugin - module = self._task.args.get('use_backend', "auto") + if 'use' in self._task.args and 'use_backend' in self._task.args: + raise AnsibleActionFail("parameters are mutually exclusive: ('use', 'use_backend')") + + module = self._task.args.get('use', self._task.args.get('use_backend', 'auto')) if module == 'auto': try: @@ -90,6 +94,8 @@ class ActionModule(ActionBase): new_module_args = self._task.args.copy() if 'use_backend' in new_module_args: del new_module_args['use_backend'] + if 'use' in new_module_args: + del new_module_args['use'] display.vvvv("Running %s as the backend for the yum action plugin" % module) result.update(self._execute_module( diff --git a/test/integration/targets/package/tasks/main.yml b/test/integration/targets/package/tasks/main.yml index 853b471199e..c8b75da4b19 100644 --- a/test/integration/targets/package/tasks/main.yml +++ b/test/integration/targets/package/tasks/main.yml @@ -143,4 +143,108 @@ - name: verify at command is installed shell: which at + - name: remove at package + package: + name: at + state: absent + register: at_install0 + + - name: validate package removal + assert: + that: + - "at_install0 is changed" + when: ansible_distribution in package_distros + +## +## yum +## +#Validation for new parameter 'use' in yum action plugin which aliases to 'use_backend' +#Issue: https://github.com/ansible/ansible/issues/70774 +- block: + - name: verify if using both the parameters 'use' and 'use_backend' throw error + yum: + name: at + state: present + use_backend: yum + use: yum + ignore_errors: yes + register: result + + - name: verify error + assert: + that: + - "'parameters are mutually exclusive' in result.msg" + - "not result is changed" + + - name: verify if package installation is successful using 'use' parameter + yum: + name: at + state: present + use: dnf + register: result + + - name: verify the result + assert: + that: + - "result is changed" + + - name: remove at package + yum: + name: at + state: absent + use: dnf + register: result + + - name: verify package removal + assert: + that: + - "result is changed" + + - name: verify if package installation is successful using 'use_backend' parameter + yum: + name: at + state: present + use_backend: dnf + register: result + + - name: verify the result + assert: + that: + - "result is changed" + + - name: remove at package + yum: + name: at + state: absent + use_backend: dnf + register: result + + - name: verify package removal + assert: + that: + - "result is changed" + + - name: verify if package installation is successful without using 'use_backend' and 'use' parameters + yum: + name: at + state: present + register: result + + - name: verify the result + assert: + that: + - "result is changed" + + - name: remove at package + yum: + name: at + state: absent + register: result + + - name: verify package removal + assert: + that: + - "result is changed" + + when: ansible_distribution == "Fedora" \ No newline at end of file