mirror of https://github.com/ansible/ansible.git
support hard coded module_defaults.yml groups for collections (#69919)
* Only allow groups which were hardcoded in module_defaults.yml only load action groups from the collection if module_defaults contains a potential group for the action * Fix tests using modules that override those whitelisted in lib/ansible/config/module_defaults.yml Third party modules should not be using group/ - use the action name instead * add externalized module_defaults tests add the missing group and collections ci_complete Co-authored-by: Matt Davis <mrd@redhat.com> * changelog ci_complete * Fix import in tests ci_complete * Update with requested changes ci_complete * don't traceback since we don't validate the contents of module_defaults ci_complete Co-authored-by: Matt Davis <mrd@redhat.com>pull/69976/head
parent
a862ff2d43
commit
51f6d129cb
@ -0,0 +1,3 @@
|
||||
bugfixes:
|
||||
- module_defaults - support short group names for content relocated to collections
|
||||
- module_defaults - support candidate action names for relocated content
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,8 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible_collections.testns.testcoll.plugins.action.echoaction import ActionModule as BaseAM
|
||||
|
||||
|
||||
class ActionModule(BaseAM):
|
||||
pass
|
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/python
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible_collections.testns.testcoll.plugins.module_utils.echo_impl import do_echo
|
||||
|
||||
|
||||
def main():
|
||||
do_echo()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,9 @@
|
||||
action_groups:
|
||||
testgroup:
|
||||
- testns.testcoll.echo1
|
||||
- testns.testcoll.echo2
|
||||
# note we can define defaults for an action
|
||||
- testns.testcoll.echoaction
|
||||
# note we can define defaults in this group for actions/modules in another collection
|
||||
- testns.othercoll.other_echoaction
|
||||
- testns.othercoll.other_echo1
|
@ -0,0 +1,19 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.action import ActionBase
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
TRANSFERS_FILES = False
|
||||
_VALID_ARGS = frozenset()
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
if task_vars is None:
|
||||
task_vars = dict()
|
||||
|
||||
result = super(ActionModule, self).run(None, task_vars)
|
||||
|
||||
result = dict(changed=False, args_in=self._task.args)
|
||||
|
||||
return result
|
@ -0,0 +1,15 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
from ansible.module_utils import basic
|
||||
from ansible.module_utils.basic import _load_params, AnsibleModule
|
||||
|
||||
|
||||
def do_echo():
|
||||
p = _load_params()
|
||||
d = json.loads(basic._ANSIBLE_ARGS)
|
||||
d['ANSIBLE_MODULE_ARGS'] = {}
|
||||
basic._ANSIBLE_ARGS = json.dumps(d).encode('utf-8')
|
||||
module = AnsibleModule(argument_spec={})
|
||||
module.exit_json(args_in=p)
|
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/python
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible_collections.testns.testcoll.plugins.module_utils.echo_impl import do_echo
|
||||
|
||||
|
||||
def main():
|
||||
do_echo()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/python
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible_collections.testns.testcoll.plugins.module_utils.echo_impl import do_echo
|
||||
|
||||
|
||||
def main():
|
||||
do_echo()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eux
|
||||
|
||||
ansible-playbook test_defaults.yml "$@"
|
@ -0,0 +1,60 @@
|
||||
- hosts: localhost
|
||||
gather_facts: no
|
||||
collections:
|
||||
- testns.testcoll
|
||||
- testns.othercoll
|
||||
module_defaults:
|
||||
testns.testcoll.echoaction:
|
||||
explicit_module_default: from playbook
|
||||
testns.testcoll.echo1:
|
||||
explicit_module_default: from playbook
|
||||
group/testgroup:
|
||||
group_module_default: from playbook
|
||||
tasks:
|
||||
- testns.testcoll.echoaction:
|
||||
task_arg: from task
|
||||
register: echoaction_fq
|
||||
- echoaction:
|
||||
task_arg: from task
|
||||
register: echoaction_unq
|
||||
- testns.testcoll.echo1:
|
||||
task_arg: from task
|
||||
register: echo1_fq
|
||||
- echo1:
|
||||
task_arg: from task
|
||||
register: echo1_unq
|
||||
- testns.testcoll.echo2:
|
||||
task_arg: from task
|
||||
register: echo2_fq
|
||||
- echo2:
|
||||
task_arg: from task
|
||||
register: echo2_unq
|
||||
- testns.othercoll.other_echoaction:
|
||||
task_arg: from task
|
||||
register: other_echoaction_fq
|
||||
- other_echoaction:
|
||||
task_arg: from task
|
||||
register: other_echoaction_unq
|
||||
- testns.othercoll.other_echo1:
|
||||
task_arg: from task
|
||||
register: other_echo1_fq
|
||||
- other_echo1:
|
||||
task_arg: from task
|
||||
register: other_echo1_unq
|
||||
|
||||
- debug: var=echo1_fq
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "echoaction_fq.args_in == {'task_arg': 'from task', 'explicit_module_default': 'from playbook', 'group_module_default': 'from playbook' }"
|
||||
- "echoaction_unq.args_in == {'task_arg': 'from task', 'explicit_module_default': 'from playbook', 'group_module_default': 'from playbook' }"
|
||||
- "echo1_fq.args_in == {'task_arg': 'from task', 'explicit_module_default': 'from playbook', 'group_module_default': 'from playbook' }"
|
||||
- "echo1_unq.args_in == {'task_arg': 'from task', 'explicit_module_default': 'from playbook', 'group_module_default': 'from playbook' }"
|
||||
- "echo2_fq.args_in == {'task_arg': 'from task', 'group_module_default': 'from playbook' }"
|
||||
- "echo2_unq.args_in == {'task_arg': 'from task', 'group_module_default': 'from playbook' }"
|
||||
- "other_echoaction_fq.args_in == {'task_arg': 'from task', 'group_module_default': 'from playbook' }"
|
||||
- "other_echoaction_unq.args_in == {'task_arg': 'from task', 'group_module_default': 'from playbook' }"
|
||||
- "other_echo1_fq.args_in == {'task_arg': 'from task', 'group_module_default': 'from playbook' }"
|
||||
- "other_echo1_unq.args_in == {'task_arg': 'from task', 'group_module_default': 'from playbook' }"
|
||||
|
||||
- include_tasks: tasks/main.yml
|
Loading…
Reference in New Issue