6

当我运行这个:

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 >>

但是使用becomefor什么是等效的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
}

PS Ansible 版本:2.6.4

4

1 回答 1

6

我必须指定--become_method su. 或者更具体地说ansible host -u myuser --become-method su --become-user otheruser -a "/bin/echo hello"

PS我通过-a "/bin/echo hello"了,因为ansible希望在更改用户后运行一些命令。

于 2018-09-22T12:29:30.053 回答