diff --git a/releasenotes/notes/zuul-return-action-plugin-152443e9183852a9.yaml b/releasenotes/notes/zuul-return-action-plugin-152443e9183852a9.yaml new file mode 100644 index 0000000000..13a47f9ab9 --- /dev/null +++ b/releasenotes/notes/zuul-return-action-plugin-152443e9183852a9.yaml @@ -0,0 +1,6 @@ +--- +upgrade: + - | + The zuul_return module has been converted to an Ansible action plugin. + Job playbooks no longer need to use delegate_to or a localhost only play + with this module as action plugin by default run on localhost. diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/zuul_return-good-delegate.yaml b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/zuul_return-good-delegate.yaml new file mode 100644 index 0000000000..8a928c695d --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/zuul_return-good-delegate.yaml @@ -0,0 +1,10 @@ +- hosts: all + tasks: + - zuul_return: + data: + zuul: + log_url: http://example.com/test/log/url/ + child: + value1: data-return + value2: data-return + delegate_to: localhost diff --git a/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/zuul_return-good.yaml b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/zuul_return-good.yaml new file mode 100644 index 0000000000..54fda7e311 --- /dev/null +++ b/tests/fixtures/config/remote-action-modules/git/org_project/playbooks/zuul_return-good.yaml @@ -0,0 +1,9 @@ +- hosts: all + tasks: + - zuul_return: + data: + zuul: + log_url: http://example.com/test/log/url/ + child: + value1: data-return + value2: data-return diff --git a/tests/remote/test_remote_action_modules.py b/tests/remote/test_remote_action_modules.py index 03922dd81b..c8198cbc9e 100644 --- a/tests/remote/test_remote_action_modules.py +++ b/tests/remote/test_remote_action_modules.py @@ -97,6 +97,12 @@ class TestActionModules(AnsibleZuulTestCase): def test_command_module(self): self._run_job('command-good', 'SUCCESS') + def test_zuul_return_module(self): + self._run_job('zuul_return-good', 'SUCCESS') + + def test_zuul_return_module_delegate_to(self): + self._run_job('zuul_return-good-delegate', 'SUCCESS') + def test_copy_module(self): self._run_job('copy-good', 'SUCCESS') diff --git a/zuul/ansible/library/zuul_return.py b/zuul/ansible/actiongeneral/zuul_return.py similarity index 71% rename from zuul/ansible/library/zuul_return.py rename to zuul/ansible/actiongeneral/zuul_return.py index 8c177195a8..f6e67a3226 100644 --- a/zuul/ansible/library/zuul_return.py +++ b/zuul/ansible/actiongeneral/zuul_return.py @@ -19,6 +19,10 @@ import os import json import tempfile +from ansible.plugins.action import ActionBase + +from zuul.ansible import paths + def merge_dict(dict_a, dict_b): """ @@ -64,25 +68,22 @@ def set_value(path, new_data, new_file): raise -def main(): - module = AnsibleModule( - argument_spec=dict( - path=dict(required=False, type='str'), - data=dict(required=False, type='dict'), - file=dict(required=False, type='str'), - ) - ) +class ActionModule(ActionBase): + def run(self, tmp=None, task_vars=None): + if task_vars is None: + task_vars = dict() + results = super(ActionModule, self).run(tmp, task_vars) + del tmp # tmp no longer has any effect - p = module.params - path = p['path'] - if not path: - path = os.path.join(os.environ['ZUUL_JOBDIR'], 'work', - 'results.json') - set_value(path, p['data'], p['file']) - module.exit_json(changed=True, e=os.environ.copy()) + path = self._task.args.get('path') + if not path: + path = os.path.join(os.environ['ZUUL_JOBDIR'], 'work', + 'results.json') -from ansible.module_utils.basic import * # noqa -from ansible.module_utils.basic import AnsibleModule + if not paths._is_safe_path(path, allow_trusted=False): + return paths._fail_dict(path) -if __name__ == '__main__': - main() + set_value( + path, self._task.args.get('data'), self._task.args.get('file')) + + return results