Merge "Convert zuul_return into action plugin"

This commit is contained in:
Zuul 2019-01-18 20:37:10 +00:00 committed by Gerrit Code Review
commit 56e79455e2
5 changed files with 51 additions and 19 deletions

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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')

View File

@ -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