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):
|
def test_command_module(self):
|
||||||
self._run_job('command-good', 'SUCCESS')
|
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):
|
def test_copy_module(self):
|
||||||
self._run_job('copy-good', 'SUCCESS')
|
self._run_job('copy-good', 'SUCCESS')
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,10 @@ import os
|
||||||
import json
|
import json
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
from ansible.plugins.action import ActionBase
|
||||||
|
|
||||||
|
from zuul.ansible import paths
|
||||||
|
|
||||||
|
|
||||||
def merge_dict(dict_a, dict_b):
|
def merge_dict(dict_a, dict_b):
|
||||||
"""
|
"""
|
||||||
|
@ -64,25 +68,22 @@ def set_value(path, new_data, new_file):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def main():
|
class ActionModule(ActionBase):
|
||||||
module = AnsibleModule(
|
def run(self, tmp=None, task_vars=None):
|
||||||
argument_spec=dict(
|
if task_vars is None:
|
||||||
path=dict(required=False, type='str'),
|
task_vars = dict()
|
||||||
data=dict(required=False, type='dict'),
|
results = super(ActionModule, self).run(tmp, task_vars)
|
||||||
file=dict(required=False, type='str'),
|
del tmp # tmp no longer has any effect
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
p = module.params
|
path = self._task.args.get('path')
|
||||||
path = p['path']
|
if not path:
|
||||||
if not path:
|
path = os.path.join(os.environ['ZUUL_JOBDIR'], 'work',
|
||||||
path = os.path.join(os.environ['ZUUL_JOBDIR'], 'work',
|
'results.json')
|
||||||
'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
|
if not paths._is_safe_path(path, allow_trusted=False):
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
return paths._fail_dict(path)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
set_value(
|
||||||
main()
|
path, self._task.args.get('data'), self._task.args.get('file'))
|
||||||
|
|
||||||
|
return results
|
Loading…
Reference in New Issue