mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ensure we have required systemd env var (#50607)
* ensure we have required systemd env var * add clarification about systemd and user scope fixes #50272
This commit is contained in:
parent
1beb6f433b
commit
a7e81ba500
2 changed files with 10 additions and 0 deletions
2
changelogs/fragments/xdg_systemd_fix.yml
Normal file
2
changelogs/fragments/xdg_systemd_fix.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- ensure we have a XDG_RUNTIME_DIR, as it is not handled correctly by some privilege escalation configurations
|
|
@ -67,6 +67,9 @@ options:
|
||||||
description:
|
description:
|
||||||
- run systemctl within a given service manager scope, either as the default system scope (system),
|
- run systemctl within a given service manager scope, either as the default system scope (system),
|
||||||
the current user's scope (user), or the scope of all users (global).
|
the current user's scope (user), or the scope of all users (global).
|
||||||
|
- "For systemd to work with 'user', the executing user must have its own instance of dbus started (systemd requirement).
|
||||||
|
The user dbus process is normally started during normal login, but not during the run of Ansible tasks.
|
||||||
|
Otherwise you will probably get a 'Failed to connect to bus: no such file or directory' error."
|
||||||
choices: [ system, user, global ]
|
choices: [ system, user, global ]
|
||||||
default: 'system'
|
default: 'system'
|
||||||
version_added: "2.7"
|
version_added: "2.7"
|
||||||
|
@ -253,6 +256,8 @@ status:
|
||||||
}
|
}
|
||||||
''' # NOQA
|
''' # NOQA
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.facts.system.chroot import is_chroot
|
from ansible.module_utils.facts.system.chroot import is_chroot
|
||||||
from ansible.module_utils.service import sysv_exists, sysv_is_enabled, fail_if_missing
|
from ansible.module_utils.service import sysv_exists, sysv_is_enabled, fail_if_missing
|
||||||
|
@ -327,6 +332,9 @@ def main():
|
||||||
|
|
||||||
systemctl = module.get_bin_path('systemctl', True)
|
systemctl = module.get_bin_path('systemctl', True)
|
||||||
|
|
||||||
|
if os.getenv('XDG_RUNTIME_DIR') is None:
|
||||||
|
os.environ['XDG_RUNTIME_DIR'] = '/run/user/%s' % os.geteuid()
|
||||||
|
|
||||||
''' Set CLI options depending on params '''
|
''' Set CLI options depending on params '''
|
||||||
if module.params['user'] is not None:
|
if module.params['user'] is not None:
|
||||||
# handle user deprecation, mutually exclusive with scope
|
# handle user deprecation, mutually exclusive with scope
|
||||||
|
|
Loading…
Reference in a new issue