2017-08-16 55 views
-2

在我的Linux機器上,系統中有三個用戶級別。ansible switch user to sudo

- base_user 
- higher_user 
- root 

我通過SSH遠程連接到機器的base_user級別。 我的ssh密鑰設置讓我可以自動作爲base_user登錄。 然後我想更改爲沒有sudo權限的higher_user。 根據安全文檔(http://docs.ansible.com/ansible/latest/become.html),成爲並且become_user需要在base_user上使用sudo才能成爲higher_user。 我不想讓higher_user或base_user具有sudo特權。

是否有任何解決方法,只是純粹做下面的ansible?

1. login as base_user with ssh key setup 
2. switch user to higher_user with password input 
+0

你叫什麼「sudo用戶」?可以sudo root的用戶?還要別的嗎? –

回答

0

sudoers文件中的此行將允許base_user使用sudo以higher_user身份運行命令。它不會允許base_user以root或任何其他用戶身份運行命令。

base_user ALL=(higher_user) ALL 

從那裏,你可以在你的劇本使用becomebecome_user

- hosts: some_host 
    become: True 
    become_user: higher_user 
    tasks: 
... 

當你運行ansible-playbook您將需要提供base_user的密碼與--ask-become-pass-K)。