繁体   English   中英

Ansible:在本地主机上以其他用户身份运行

[英]Ansible: Run as a different user on localhost

我想使用ansible_connection=local在本地主机上运行命令,但也要以特定用户身份使用,即ansible_user=my_other_user 有趣的是,这两个选项似乎是互斥的:

  • /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登录到localhost,而无需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运行命令。

become了这样:

ubuntu@test:/$ ansible all -i 'localhost,' -c local -m shell -a 'whoami'
localhost | SUCCESS | rc=0 >>
ubuntu

ubuntu@test:/$ ansible all -i 'localhost,' -c local -b --become-user=www-data -m shell -a 'whoami'
localhost | SUCCESS | rc=0 >>
www-data

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM