对非特权用户的ansible become_user失败

时间:2016-08-02 21:42:56

标签: ansible google-compute-engine sudo

我正在使用ansible脚本在远程创建目录。当我同时使用become和become_user时,这似乎失败了。请注意,我正在使用特权用户登录该框,其他命令(没有become_user)似乎工作正常。任何用户deploy ALL=NOPASSWD: ALL

都没有密码集
# This works
- name: create log directory
  file: path={{ log_directory }} state=directory owner=metax group=metax mode=0755
  become: yes 

# This fails
- name: create log directory
  file: path={{ log_directory }} state=directory owner=metax group=metax mode=0755
  become: yes
  become_user: deploy

失败并显示错误:

fatal: [node0]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_name": "file"}, "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}

我还尝试按照ansible文档中的描述启用管道传输: https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user

1 个答案:

答案 0 :(得分:0)

从ansible文档中,您可以使用以下命令定义成为此用户的方法:

become_method

at play or task level overrides the default method set in ansible.cfg, set to ‘sudo’/’su’/’pbrun’/’pfexec’/’doas’/’dzdo’

这意味着部署用户不在sudoers中。尝试类似 su

的内容