代码之家  ›  专栏  ›  技术社区  ›  Andrius

Ansible:考虑使用“been”、“been\u method”和“been\u user”,而不是运行sudo

  •  2
  • Andrius  · 技术社区  · 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 >>
    

    但如果使用 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

    1 回复  |  直到 6 年前
        1
  •  6
  •   Andrius    6 年前

    我必须详细说明 --become_method su ansible host -u myuser --become-method su --become-user otheruser -a "/bin/echo hello"

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

    推荐文章