mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
make: allow multiple targets to be specified (#6882)
* make: allow multiple targets to be specified * add changelog frag * Update changelogs/fragments/6882-make-multiple-targets.yml Co-authored-by: Felix Fontein <felix@fontein.de> * change to extra param * adjust changelog frag --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
7609cebae9
commit
0ae8f9d631
2 changed files with 25 additions and 4 deletions
2
changelogs/fragments/6882-make-multiple-targets.yml
Normal file
2
changelogs/fragments/6882-make-multiple-targets.yml
Normal file
|
@ -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).
|
|
@ -54,7 +54,16 @@ options:
|
||||||
description:
|
description:
|
||||||
- The target to run.
|
- The target to run.
|
||||||
- Typically this would be something like V(install), V(test), or V(all).
|
- Typically this would be something like V(install), V(test), or V(all).
|
||||||
|
- O(target) and O(targets) are mutually exclusive.
|
||||||
type: str
|
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'''
|
EXAMPLES = r'''
|
||||||
|
@ -115,6 +124,12 @@ target:
|
||||||
- The value of the module parameter O(target).
|
- The value of the module parameter O(target).
|
||||||
type: str
|
type: str
|
||||||
returned: success
|
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
|
from ansible.module_utils.six import iteritems
|
||||||
|
@ -155,12 +170,14 @@ def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
target=dict(type='str'),
|
target=dict(type='str'),
|
||||||
|
targets=dict(type='list', elements='str'),
|
||||||
params=dict(type='dict'),
|
params=dict(type='dict'),
|
||||||
chdir=dict(type='path', required=True),
|
chdir=dict(type='path', required=True),
|
||||||
file=dict(type='path'),
|
file=dict(type='path'),
|
||||||
make=dict(type='path'),
|
make=dict(type='path'),
|
||||||
jobs=dict(type='int'),
|
jobs=dict(type='int'),
|
||||||
),
|
),
|
||||||
|
mutually_exclusive=[('target', 'targets')],
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -172,7 +189,6 @@ def main():
|
||||||
if not make_path:
|
if not make_path:
|
||||||
# Fall back to system make
|
# Fall back to system make
|
||||||
make_path = module.get_bin_path('make', required=True)
|
make_path = module.get_bin_path('make', required=True)
|
||||||
make_target = module.params['target']
|
|
||||||
if module.params['params'] is not None:
|
if module.params['params'] is not None:
|
||||||
make_parameters = [k + '=' + str(v) for k, v in iteritems(module.params['params'])]
|
make_parameters = [k + '=' + str(v) for k, v in iteritems(module.params['params'])]
|
||||||
else:
|
else:
|
||||||
|
@ -188,7 +204,10 @@ def main():
|
||||||
base_command.extend(["-f", module.params['file']])
|
base_command.extend(["-f", module.params['file']])
|
||||||
|
|
||||||
# add make target
|
# 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
|
# add makefile parameters
|
||||||
base_command.extend(make_parameters)
|
base_command.extend(make_parameters)
|
||||||
|
@ -206,8 +225,7 @@ def main():
|
||||||
changed = False
|
changed = False
|
||||||
else:
|
else:
|
||||||
# The target isn't up to date, so we need to run it
|
# The target isn't up to date, so we need to run it
|
||||||
rc, out, err = run_command(base_command, module,
|
rc, out, err = run_command(base_command, module, check_rc=True)
|
||||||
check_rc=True)
|
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
# We don't report the return code, as if this module failed
|
# We don't report the return code, as if this module failed
|
||||||
|
@ -221,6 +239,7 @@ def main():
|
||||||
stdout=out,
|
stdout=out,
|
||||||
stderr=err,
|
stderr=err,
|
||||||
target=module.params['target'],
|
target=module.params['target'],
|
||||||
|
targets=module.params['targets'],
|
||||||
params=module.params['params'],
|
params=module.params['params'],
|
||||||
chdir=module.params['chdir'],
|
chdir=module.params['chdir'],
|
||||||
file=module.params['file'],
|
file=module.params['file'],
|
||||||
|
|
Loading…
Reference in a new issue