在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 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

http://docs.ansible.com/ansible/become.html

点赞