运行此命令时:
ansible host -u myuser -a "sudo su - otheruser -s /bin/bash"
我得到警告:
[WARNING]: Consider using 'become', 'become_method', and 'become_user' rather
than running sudo
host | SUCCESS | rc=0 >>
但是将become
用于sudo su - otheruser -s /bin/bash
会等同于什么?
我尝试过:
ansible host -u myuser --become --become-user otheruser -a "/bin/echo hello"
但是我得到了
host | FAILED! => {
"changed": false,
"module_stderr": "Shared connection to host closed.\r\n",
"module_stdout": "sudo: a password is required\r\n",
"msg": "MODULE FAILURE",
"rc": 1
}
P.S。 Ansible版本:2.6.4
答案 0 :(得分:4)
我必须指定--become_method su
。或更具体地说,ansible host -u myuser --become-method su --become-user otheruser -a "/bin/echo hello"
P.S。我正在传递-a "/bin/echo hello"
,因为ansible希望在更改用户后运行一些命令。