-
Notifications
You must be signed in to change notification settings - Fork 24.1k
[WIP] Add the ability to specify --root. #58017
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
base: devel
Are you sure you want to change the base?
Conversation
When systemd is not running but changes has to be made such as enabling or disabling services, using `--root` allows us to run systemctl without it. This PR adds the ability to do just that. (cherry picked from commit 5932c05) Also fix how scope is added, it should ony be needed with commands that use a 'unit'
| if module.params['force']: | ||
| systemctl += " --force" | ||
|
|
||
| unit = module.params['name'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed since the same line has been added recently: https://github.com/ansible/ansible/blob/83bf90e/lib/ansible/modules/system/systemd.py#L343
mkrizek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor 'issue', looks good otherwise.
tchernomax
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also (but not related to this PR):
Line 481→485:
if module.params['scope'] in (None, 'system') and \
not module.params['user'] and \
is_initd and \
not out.strip().endswith('disabled') and \
sysv_is_enabled(unit):
This code "fail" on the following configuration ; it detect the service as enabled, even the init.d service is supersede by the systemd service… and disabled:
root@test ~ # l /etc/init.d/toto /etc/rc5.d/S99toto /etc/systemd/system/toto.service
-rwxr-xr-x 1 root root 24 Jul 6 13:38 /etc/init.d/toto
lrwxrwxrwx 1 root root 16 Jul 6 13:42 /etc/rc5.d/S99toto -> /etc/init.d/toto
-rw-r--r-- 1 root root 74 Jul 6 13:41 /etc/systemd/system/toto.service
root@test ~ # systemctl is-enabled toto
disabled
Line 442:
module.warn('The service (%s) is actually an init script but the system is managed by systemd' % unit)
This warning is only triggered when you add an /etc/init.d/… file and don't daemon-reload.
It isn't throw every time/configuration when the service is "an init script but the system is managed by systemd".
Line 447:
masked = ('LoadState' in result['status'] and result['status']['LoadState'] == 'masked')
Just use is_masked (be sure to initialize it).
Also it doesn't work on chroot environment (when list-unit-files is used)
| # The other choices match the corresponding switch | ||
| if module.params['scope'] not in (None, 'system'): | ||
| systemctl += " --%s" % module.params['scope'] | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if scope=user or scope=global, and daemon_reload=true or daemon_rexec=true → ansible will try to daemon-reload or daemon-rexec the system daemon (instead of the user one).
| is_systemd = False | ||
|
|
||
| if module.params['root']: | ||
| systemctl_unit += " --root=%s" % module.params['root'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fail if scope=user.
(root and scope=user are incompatible)
|
|
||
| # check service data, cannot error out on rc as it changes across versions, assume not found | ||
| (rc, out, err) = module.run_command("%s show '%s'" % (systemctl, unit)) | ||
| (rc, out, err) = module.run_command("%s show '%s'" % (systemctl_unit, unit)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fail if root is used:
show seams not to take into account the --root parameter, so we are "showing" the wrong unit.
max@mde-oxalide % sudo systemctl --root /var/lib/machines/arch-64-tmp/ show org.cups.cupsd.service | grep LoadState
LoadState=loaded
max@mde-oxalide % sudo find /var/lib/machines/arch-64-tmp/ -name org.cups.cupsd.service
max@mde-oxalide %
| result['changed'] = True | ||
| if not module.check_mode: | ||
| (rc, out, err) = module.run_command("%s %s '%s'" % (systemctl, action, unit)) | ||
| (rc, out, err) = module.run_command("%s %s '%s'" % (systemctl_unit, action, unit)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fail if root is used.
When systemd is not running but changes has to be made such as enabling or disabling services,
using
--rootallows us to run systemctl without it.This PR adds the ability to do just that.
(cherry picked from commit 5932c05)
rebase and fix for #44690
Also fix how scope is added, it should ony be needed with commands that use a 'unit'
ISSUE TYPE
COMPONENT NAME
systemd