community.general.machinectl become – Systemd 的 machinectl 权限提升

注意

此 become 插件是 community.general 集合 (版本 10.1.0) 的一部分。

如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用: ansible-galaxy collection install community.general

要在 playbook 中使用它,请指定: community.general.machinectl

概要

  • 此 become 插件允许您的远程/登录用户通过 machinectl 实用程序以另一个用户的身份执行命令。

参数

参数

注释

become_exe

字符串

Machinectl 可执行文件。

默认值: "machinectl"

配置

  • INI 条目

    [privilege_escalation]
    become_exe = machinectl
    
    [machinectl_become_plugin]
    executable = machinectl
    
  • 环境变量:ANSIBLE_BECOME_EXE

  • 环境变量:ANSIBLE_MACHINECTL_EXE

  • 变量:ansible_become_exe

  • 变量:ansible_machinectl_exe

become_flags

字符串

传递给 machinectl 的选项。

默认值: ""

配置

  • INI 条目

    [privilege_escalation]
    become_flags = ""
    
    [machinectl_become_plugin]
    flags = ""
    
  • 环境变量:ANSIBLE_BECOME_FLAGS

  • 环境变量:ANSIBLE_MACHINECTL_FLAGS

  • 变量:ansible_become_flags

  • 变量:ansible_machinectl_flags

become_pass

字符串

machinectl 的密码。

配置

  • INI 条目

    [machinectl_become_plugin]
    password = VALUE
    
  • 环境变量:ANSIBLE_BECOME_PASS

  • 环境变量:ANSIBLE_MACHINECTL_PASS

  • 变量:ansible_become_password

  • 变量:ansible_become_pass

  • 变量:ansible_machinectl_pass

become_user

字符串

您“成为”以执行任务的用户。

默认值: ""

配置

  • INI 条目

    [privilege_escalation]
    become_user = ""
    
    [machinectl_become_plugin]
    user = ""
    
  • 环境变量:ANSIBLE_BECOME_USER

  • 环境变量:ANSIBLE_MACHINECTL_USER

  • 变量:ansible_become_user

  • 变量:ansible_machinectl_user

备注

注意

  • 当不与用户 root一起使用此插件时,它仅与将更改 machinectl 行为的 polkit 规则一起正常工作。此规则必须更改提示行为以直接询问用户凭据,如果允许用户执行操作(请查看示例部分)。如果不存在此类规则,则只有在与 root 用户一起使用时,插件才能工作,因为那时 machinectl 将不会显示任何其他提示。

示例

# A polkit rule needed to use the module with a non-root user.
# See the Notes section for details.
/etc/polkit-1/rules.d/60-machinectl-fast-user-auth.rules: |
  polkit.addRule(function(action, subject) {
    if(action.id == "org.freedesktop.machine1.host-shell" &&
      subject.isInGroup("wheel")) {
        return polkit.Result.AUTH_SELF_KEEP;
    }
  });

作者

  • Ansible核心团队

提示

每种条目类型的配置条目具有从低到高的优先级顺序。例如,列表中较低的变量将覆盖较高的变量。