在sudoing时失踪成为密码

时间:2015-11-22 21:56:20

标签: ansible sudo

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

这是我的剧本:

Function GetColors(i, j) As Collection
Dim l&, k&, r As Range
Dim c As Collection
Set c = New Collection
Set r = ActiveSheet.Cells(i, j)
Do
    l = Len(r)
    If Not InStr(r, ",") Then
        k = InStr(k + 1, r, ",")
    ElseIf Not InStr(r, " / ") Then
        k = InStr(k + 1, r, " / ")
    End If
    If k Then l = k - 1
    c.Add r.Characters(l, 1).Font.ColorIndex
Loop Until k = 0
Set GetColors = c
End Function

我希望whoami为--- - hosts: production gather_facts: no remote_user: deployer become: yes become_method: sudo become_user: root tasks: - name: Whoami command: /usr/bin/whoami ,但任务失败并显示错误消息:

root

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

» 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

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

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

- 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}} 是我希望使用以下python片段进行哈希的密码:

{{ansible_become_pass}}

python -c 'import crypt; print crypt.crypt("password I desire", "$1$SomeSalt$")' 替换为密码,"password I desire"是随机盐。

我使用的是Ansible 1.9.4版。

问题是什么?

1 个答案:

答案 0 :(得分: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