mirror of https://github.com/ansible/ansible.git
PluginLoader now installs module-to-be-imported in sys.modules before exec (as Python import does). (#78364)
parent
0ef1376966
commit
1368bfa348
@ -0,0 +1,2 @@
|
|||||||
|
bugfixes:
|
||||||
|
- Fix PluginLoader to mimic Python import machinery by adding module to sys.modules before exec
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
# Copyright: Contributors to the Ansible project
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
from ansible.plugins.action import ActionBase
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# reference our own module from sys.modules while it's being loaded to ensure the importer behaves properly
|
||||||
|
try:
|
||||||
|
mod = sys.modules[__name__]
|
||||||
|
except KeyError:
|
||||||
|
raise Exception(f'module {__name__} is not accessible via sys.modules, likely a pluginloader bug')
|
||||||
|
|
||||||
|
|
||||||
|
class ActionModule(ActionBase):
|
||||||
|
TRANSFERS_FILES = False
|
||||||
|
|
||||||
|
def run(self, tmp=None, task_vars=None):
|
||||||
|
if task_vars is None:
|
||||||
|
task_vars = dict()
|
||||||
|
|
||||||
|
result = super(ActionModule, self).run(tmp, task_vars)
|
||||||
|
del tmp # tmp no longer has any effect
|
||||||
|
|
||||||
|
result['changed'] = False
|
||||||
|
result['msg'] = 'self-referential action loaded and ran successfully'
|
||||||
|
return result
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
- hosts: testhost
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: ensure a self-referential action plugin loads properly
|
||||||
|
self_referential:
|
||||||
Loading…
Reference in New Issue