Merge "Convert zuul_return into action plugin"
This commit is contained in:
commit
56e79455e2
@ -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.
|
@ -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
|
9
tests/fixtures/config/remote-action-modules/git/org_project/playbooks/zuul_return-good.yaml
vendored
Normal file
9
tests/fixtures/config/remote-action-modules/git/org_project/playbooks/zuul_return-good.yaml
vendored
Normal 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
|
@ -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')
|
||||
|
||||
|
@ -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']
|
||||
path = self._task.args.get('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())
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user