登录Ansible后切换用户

登录Ansible后切换用户,ansible,Ansible,我需要以root用户身份运行各种ansible任务,但由于安全限制,我只能通过运行命令“super su root”并键入密码来实现。不允许sudo。登录后可以这样切换用户吗?可以: Directives These can be set from play to task level, but are overriden by connection variables as they can be host specific. become set to ‘true’/’yes’ to a

我需要以root用户身份运行各种ansible任务,但由于安全限制,我只能通过运行命令“super su root”并键入密码来实现。不允许sudo。登录后可以这样切换用户吗?

可以:

Directives

These can be set from play to task level, but are overriden by connection variables as they can be host specific.

become
set to ‘true’/’yes’ to activate privilege escalation.

become_user
set to user with desired privileges, the user you ‘become’, NOT the user you login as. Does NOT imply become: yes, to allow it to be set at host level.

become_method
at play or task level overrides the default method set in ansible.cfg, set to ‘sudo’/’su’/’pbrun’/’pfexec’/’doas’

Connection variables
Each allows you to set an option per group and/or host, these are normally defined in inventory but can be used as normal variables.

ansible_become
equivalent of the become directive, decides if privilege escalation is used or not.

ansible_become_method
allows to set privilege escalation method

ansible_become_user
allows to set the user you become through privilege escalation, does not imply ansible_become: True

ansible_become_pass
allows you to set the privilege escalation password

Ansible已经从使用
sudo
过渡到精确地支持这样的用例


您可能需要为您的
super
命令实现,或者要求Ansible团队为您实现。

Been不起作用,因为这需要某种形式的sudo(即,以另一个用户的身份运行命令,但不要切换用户)。在使用“super-su-root”命令执行任何其他任务之前,我需要切换到root。您的ansible版本是什么?从源代码构建,所以是最新的。我认为
been
在这里不起作用。从您的链接:“要使用的权限提升方法(默认值=sudo),有效选项:[sudo | su | pbrun | pfexec | doas]”。似乎不能为此设置任意命令。对,我建议OP必须在ansible本身中实现对其命令的支持。每个实现似乎只有几行相当简单的代码,并且它们已经从源代码构建ansible,因此虽然这显然不是一个理想的解决方案,但它可能是最容易处理它们的情况的方法。通过使用
been_exe
(这是一个未记录的特性)已经可以做到这一点,但这并不能解决问题,因为我根本不能使用BEGINE范式。我使用的命令将切换用户,而不是以其他用户的身份运行该命令。