Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subcommands parameter for module alternatives. #4654

Merged
merged 28 commits into from
Jun 6, 2022
Merged
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fad8c09
Add slaves parameter for module alternatives.
jiuka May 9, 2022
b7606a5
alternatives: Improve documentation abous slaves parameter
jiuka May 9, 2022
88a00ae
alternatives: Apply suggestions from code review
jiuka May 10, 2022
fc2b694
alternatives: Add schangelog for slaves parameter
jiuka May 10, 2022
910e7fe
alernatives: Add integration tests
jiuka May 10, 2022
b3658ed
alternatives: Improv tests
jiuka May 11, 2022
197e98c
alternatives: Update tests/integration/targets/alternatives/tasks/sla…
jiuka May 11, 2022
81cf47d
alternatives: Rework logic to support updating priority and subcommands
jiuka May 12, 2022
4516c88
alternatives: Use more inclusive naming
jiuka May 12, 2022
8ee5cfd
alternatives: Fix linter warnings
jiuka May 12, 2022
7ff3983
alternatives: Dont fail if link is absent
jiuka May 12, 2022
e9a128f
alternatives: Update changelog fragment
jiuka May 12, 2022
c242382
alternatives: Add tests for prio change and removing
jiuka May 13, 2022
63e1d2c
alternatives: Apply suggestions from code review
jiuka May 13, 2022
aaf2a83
alternatives: Add `state=auto`to reset mode to auto
jiuka May 13, 2022
87b9f66
alternatives: Fix linter warnings
jiuka May 13, 2022
708ef3e
alternatives: Fix documentation.
jiuka May 14, 2022
851be5e
alternatives: Combine multiple messages.
jiuka May 14, 2022
56a09b7
alternatives: Set command env for all commands.
jiuka May 14, 2022
6ef4b5f
alternatives: Do not update subcommands if parameter is omited
jiuka May 14, 2022
66a7b3d
alternatives: Fix a bug with python 2.7 var scoping
jiuka May 15, 2022
e2751ce
alternatives: Improce diff before generation
jiuka May 15, 2022
1935016
alternatives: Fix linter warnings
jiuka May 15, 2022
b30160b
alternatives: Fix test names
jiuka May 16, 2022
8ed1836
alternatives: Simplify subcommands handling and improve diffs
jiuka May 16, 2022
8c2fa33
aliases: Only test for subcommand changes if subcommands parameter is…
jiuka May 16, 2022
069eed7
Update plugins/modules/system/alternatives.py
jiuka May 17, 2022
abd45ff
Apply suggestions from code review
felixfontein May 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion plugins/modules/system/alternatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@
default: selected
type: str
version_added: 4.8.0
slaves:
description:
- A list of slaves
- Each slave needs a name, a link and a path parameter
jiuka marked this conversation as resolved.
Show resolved Hide resolved
type: list
elements: dict
suboptions:
name:
description:
- The generic name of the slave.
type: str
required: true
path:
description:
- The path to the real executable that the slave should point to.
type: path
required: true
link:
description:
- The path to the symbolic link that should point to the real slave executable.
type: path
version_added: 2.5.0
jiuka marked this conversation as resolved.
Show resolved Hide resolved
requirements: [ update-alternatives ]
'''

Expand Down Expand Up @@ -78,6 +100,16 @@
path: /usr/bin/python3.5
link: /usr/bin/python
state: present

- name: keytool is a slave of java
alternatives:
jiuka marked this conversation as resolved.
Show resolved Hide resolved
name: java
link: /usr/bin/java
path: /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
slaves:
- name: keytool
link: /usr/bin/keytool
path: /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/keytool
'''

import os
Expand Down Expand Up @@ -109,6 +141,7 @@ def main():
choices=AlternativeState.to_list(),
default=AlternativeState.SELECTED,
),
slaves=dict(type='list', elements='dict'),
jiuka marked this conversation as resolved.
Show resolved Hide resolved
),
supports_check_mode=True,
)
Expand Down Expand Up @@ -180,8 +213,13 @@ def main():
if not link:
module.fail_json(msg="Needed to install the alternative, but unable to do so as we are missing the link")

cmd = [UPDATE_ALTERNATIVES, '--install', link, name, path, str(priority)]
if params['slaves']:
slaves = map(lambda slave: ['--slave', slave['link'], slave['name'], slave['path']], params['slaves'])
jiuka marked this conversation as resolved.
Show resolved Hide resolved
cmd += [item for sublist in slaves for item in sublist]

module.run_command(
[UPDATE_ALTERNATIVES, '--install', link, name, path, str(priority)],
cmd,
check_rc=True
)
changed = True
Expand Down