diff --git a/changelogs/fragments/6882-make-multiple-targets.yml b/changelogs/fragments/6882-make-multiple-targets.yml new file mode 100644 index 0000000000..f870659f89 --- /dev/null +++ b/changelogs/fragments/6882-make-multiple-targets.yml @@ -0,0 +1,2 @@ +minor_changes: + - make - add new ``targets`` parameter allowing multiple targets to be used with ``make`` (https://github.com/ansible-collections/community.general/pull/6882, https://github.com/ansible-collections/community.general/issues/4919). diff --git a/plugins/modules/make.py b/plugins/modules/make.py index 1bc62925f5..665457fd6d 100644 --- a/plugins/modules/make.py +++ b/plugins/modules/make.py @@ -54,7 +54,16 @@ options: description: - The target to run. - Typically this would be something like V(install), V(test), or V(all). + - O(target) and O(targets) are mutually exclusive. type: str + targets: + description: + - The list of targets to run. + - Typically this would be something like V(install), V(test), or V(all). + - O(target) and O(targets) are mutually exclusive. + type: list + elements: str + version_added: 7.2.0 ''' EXAMPLES = r''' @@ -115,6 +124,12 @@ target: - The value of the module parameter O(target). type: str returned: success +targets: + description: + - The value of the module parameter O(targets). + type: str + returned: success + version_added: 7.2.0 ''' from ansible.module_utils.six import iteritems @@ -155,12 +170,14 @@ def main(): module = AnsibleModule( argument_spec=dict( target=dict(type='str'), + targets=dict(type='list', elements='str'), params=dict(type='dict'), chdir=dict(type='path', required=True), file=dict(type='path'), make=dict(type='path'), jobs=dict(type='int'), ), + mutually_exclusive=[('target', 'targets')], supports_check_mode=True, ) @@ -172,7 +189,6 @@ def main(): if not make_path: # Fall back to system make make_path = module.get_bin_path('make', required=True) - make_target = module.params['target'] if module.params['params'] is not None: make_parameters = [k + '=' + str(v) for k, v in iteritems(module.params['params'])] else: @@ -188,7 +204,10 @@ def main(): base_command.extend(["-f", module.params['file']]) # add make target - base_command.append(make_target) + if module.params['target']: + base_command.append(module.params['target']) + elif module.params['targets']: + base_command.extend(module.params['targets']) # add makefile parameters base_command.extend(make_parameters) @@ -206,8 +225,7 @@ def main(): changed = False else: # The target isn't up to date, so we need to run it - rc, out, err = run_command(base_command, module, - check_rc=True) + rc, out, err = run_command(base_command, module, check_rc=True) changed = True # We don't report the return code, as if this module failed @@ -221,6 +239,7 @@ def main(): stdout=out, stderr=err, target=module.params['target'], + targets=module.params['targets'], params=module.params['params'], chdir=module.params['chdir'], file=module.params['file'],