背景:
linux 机器都禁止root用户远程直接登录,需要ansible切换用户来实现
配置 /etc/ansible/hosts
[test]
192.168.55.65 ansible_ssh_user=vmuser ansible_ssh_pass='112233' ansible_become_pass='778899'
192.168.55.66 ansible_ssh_user=vmuser ansible_ssh_pass='112233' ansible_become_pass='778899'
192.168.55.67 ansible_ssh_user=vmuser ansible_ssh_pass='112233' ansible_become_pass='778899'
192.168.55.68 ansible_ssh_user=vmuser ansible_ssh_pass='112233' ansible_become_pass='778899'
192.168.55.69 ansible_ssh_user=vmuser ansible_ssh_pass='112233' ansible_become_pass='778899'
192.168.55.70 ansible_ssh_user=vmuser ansible_ssh_pass='112233' ansible_become_pass='778899'
192.168.55.71 ansible_ssh_user=vmuser ansible_ssh_pass='112233' ansible_become_pass='778899'
192.168.55.72 ansible_ssh_user=vmuser ansible_ssh_pass='112233' ansible_become_pass='778899'
[root@cloud_web59 / ]# ansible test -S -R root -m shell -a ‘whoami’
或者 ansible test -m shell -a “whomi” -b
参数: 新版本使用-b 替换了 -S -R root
-S 表示sudo
-R 表示 -su-user=SU_USER
(需要注意的是,这里的普通用户的家目录要存在)
文章来源:https://www.cnaaa.net,转载请注明出处:https://www.cnaaa.net/archives/7072