在剧本中,我使用sudo复制文件。它曾经可以工作...直到我们迁移到Ansible 1.9 ...此后,它失败并显示以下错误消息:

“ssh连接已关闭,正在等待sudo密码提示”

我提供了ssh和sudo密码(通过Ansible提示符),并且通过sudo运行的所有其他命令均成功(仅文件复制和模板失败)。

我的命令是:

ansible-playbook -k --ask-become-pass --limit = testhost -C -D playbooks/debug.yml

剧本包含:

- hosts: designsync

  gather_facts: yes

  tasks:
    - name: Make sure the syncmgr home folder exists
       action: file path=/home/syncmgr owner=syncmgr group=syncmgr mode=0755 state=directory
      sudo: yes
      sudo_user: syncmgr

    - name: Copy .cshrc file
      action: copy src=roles/designsync/files/syncmgr.cshrc dest=/home/syncmgr/.cshrc owner=syncmgr group=syncmgr mode=0755
      sudo: yes
      sudo_user: syncmgr

这是一个错误还是我错过了什么?

弗朗索瓦

最佳答案

您的剧本应如下所示:

- hosts: designsync

  gather_facts: yes

  tasks:
    - name: Make sure the syncmgr home folder exists
      sudo: yes
      sudo_user: syncmgr
      file:
        path: "/home/syncmgr"
        owner: syncmgr
        group: syncmgr
        mode: 0755
        state: directory

    - name: Copy .cshrc file
      sudo: yes
      sudo_user: syncmgr
      copy:
        src: "roles/designsync/files/syncmgr.cshrc"
        dest: "/home/syncmgr/.cshrc"
        owner: syncmgr
        group: syncmgr
        mode: 0755

10-06 00:59