2017-08-17 77 views
1

我想在本地主機上運行命令,使用ansible_connection=local,但也可以作爲特定用戶,即ansible_user=my_other_user。有趣的是,兩個選擇似乎是相互排斥的:Ansible:作爲本地主機上的其他用戶運行

  • 隨着/etc/ansible/hostslocalhost ansible_user=my_other_user
    • ansible localhost -a "whoami" localhost | SUCCESS | rc=0 >> my_other_user
  • 隨着/etc/ansible/hostslocalhost ansible_user=my_other_user ansible_connection=local
    • ansible localhost -a "whoami" localhost | SUCCESS | rc=0 >> myself

這是錯誤還是功能?

如何使用配置Ansible的清單使用my_other_user登錄到本地主機,但不需要ssh?

編輯:這應該永遠不會使用sudo通過本地用戶myself。用戶myselfmy_other_user的密碼是不同的,Ansible不知道密碼myself

EDIT2:改變到方法su(即localhost ansible_connection=local ansible_become_user=my_other_user ansible_become_method=su ansible_become=true)不工作,因爲它然後不可能不知道根密碼作爲root運行命令。

回答

0

become爲:因爲它需要用戶`ubuntu`密碼

[email protected]:/$ ansible all -i 'localhost,' -c local -m shell -a 'whoami' 
localhost | SUCCESS | rc=0 >> 
ubuntu 

[email protected]:/$ ansible all -i 'localhost,' -c local -b --become-user=www-data -m shell -a 'whoami' 
localhost | SUCCESS | rc=0 >> 
www-data 
+0

這種解決方案並沒有爲我工作,但我需要Ansible使用sudo密碼'WWW-data'。編輯的問題更精確。 – Kalsan

相關問題