首页 文章

在sudoing时失踪成为密码

提问于
浏览
9

当我尝试在我的Ansible playbook中使用sudo运行任务时,我看到一条错误消息 .

这是我的剧本:

---
- hosts: production
  gather_facts: no
  remote_user: deployer
  become: yes
  become_method: sudo
  become_user: root

  tasks:
    - name: Whoami
      command: /usr/bin/whoami

我希望whoami是 root 但任务失败并显示错误消息:

» ansible-playbook -i ansible_hosts sudo.yml --ask-sudo-pass
SUDO password: [I paste my sudo password here]

PLAY [production] *************************************************************

GATHERING FACTS ***************************************************************
fatal: [MY.IP] => Missing become password

TASK: [Whoami] ****************************************************************
FATAL: no hosts matched or all hosts have already failed -- aborting

当我手动ssh到框中并尝试sudo它按预期工作:

» ssh deployer@production
» sudo whoami
[I paste the same sudo password]
root

部署者用户密码由Ansible设置如下(在不同的剧本中):

- hosts: production
  remote_user: root

  # The {{ansible_become_pass}} comes from this file:
  vars_files:
    - ./config.yml

  tasks:

    - name: Create deployer user
      user: name=deployer uid=1040 groups=sudo,deployer shell=/bin/bash password={{ansible_become_pass}}

{{ansible_become_pass}} 是我希望使用以下python片段进行哈希处理的密码:

python -c 'import crypt; print crypt.crypt("password I desire", "$1$SomeSalt$")'

"password I desire" 替换为密码, "$1$SomeSalt$" 是随机盐 .

我正在使用Ansible 1.9.4版 .

有什么问题?

1 回答

  • 4

    我已经尝试了你的版本和playbook,只有 --ask-pass ,它返回 "stdout": "root" 结果 .

    您必须将 --ask-sudo-pass 替换为 --ask-pass . 并确保您的部署用户具有root权限 .

    $ ./bin/ansible --version
    ansible 1.9.4
    $ ./ansible/bin/ansible-playbook -vv pl.yml --ask-pass 
    SSH password: 
    
    PLAY [localhost] ************************************************************** 
    
    TASK: [Whoami] **************************************************************** 
    <localhost> REMOTE_MODULE command /usr/bin/whoami
    changed: [localhost] => {"changed": true, "cmd": ["/usr/bin/whoami"], "delta": "0:00:00.002555", "end": "2015-12-05 07:17:16.634485", "rc": 0, "start": "2015-12-05 07:17:16.631930", "stderr": "", "stdout": "root", "warnings": []}
    
    PLAY RECAP ******************************************************************** 
    localhost                  : ok=1    changed=1    unreachable=0    failed=0
    

相关问题