Ansible:考虑使用 'become'、'become_method' 和 'become_user' 而不是 运行 sudo
Ansible: Consider using 'become', 'become_method', and 'become_user' rather than running sudo
当我运行这个:
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
我必须指定 --become_method su
。或者更具体地说 ansible host -u myuser --become-method su --become-user otheruser -a "/bin/echo hello"
P.S。我正在传递 -a "/bin/echo hello"
,因为 ansible 期望在更改用户后 运行 一些命令。
当我运行这个:
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
我必须指定 --become_method su
。或者更具体地说 ansible host -u myuser --become-method su --become-user otheruser -a "/bin/echo hello"
P.S。我正在传递 -a "/bin/echo hello"
,因为 ansible 期望在更改用户后 运行 一些命令。