首页 > 解决方案 > Ansible Synchronize 模块在测试时卡住

问题描述

目标:我正在尝试/home/foo/certificates/*/{fullchain.cer,*.key} 从一台服务器(tower.example.com)复制到其他节点。

使用verbose选项尝试任务时,它被卡住了。可以在那里找到输出日志(Ansible 2.5):https ://gist.github.com/tristanbes/1be96509d4853d647a49d30259672779

- hosts: staging:web:tower:!tower.example.com
  gather_facts: yes
  become: yes
  become_user: foo
  tasks:
    - name: synchronize the certificates folder
      synchronize:
        src: "/home/foo/certificates/"
        dest: "{{ certificates_path }}/"
        rsync_opts:
          - "--include=fullchain.cer"
          - "--include=*.key"
      delegate_to: tower.example.com

我在本地主机上运行这个剧本。我除此之外是foo在那时连接,到组服务器的tower.example.comssh和rsync 推送与过滤器匹配的文件夹的内容。foowebstaging

我错过了什么?

标签: ansible

解决方案


看起来tower.example.com可能没有对其他主机的 ssh 访问权限。这会导致 Ansible 在 ssh 等待密码时卡住。您可以通过以下方式解决此问题

  • 在其他主机上生成新的 ssh 密钥tower.example.com并对其进行授权,和/或
  • 设置ssh-agent 转发

或者,您可以将证书提取到临时文件夹localhost并将它们复制到其他主机。这避免了使用delegate_to,但不如直接在远程主机之间同步文件高效。


推荐阅读