【问题标题】:Ansible Synchronize does not respect delegate_to | Rsync from and to the control machineAnsible Synchronize 不尊重 delegate_to |与控制机器之间的 Rsync
【发布时间】:2017-08-29 15:40:20
【问题描述】:

我需要将一个目录从控制机器同步到控制机器(源和目标是本地主机)。我遵循指令here 并在脚本中添加了delegate_to: localhost。尽管如此,同步指令尝试使用远程机器作为目标并失败。

- name: Copy node_modules over if exists
  synchronize:
    src: "{{ node_modules_path }}"
    dest: "{{ deploy_helper.new_release_path }}/{{ deploy_app_name }}/"
  become: true
  become_method: sudo
  delegate_to: localhost
  run_once: true
  when: node_modules.stat.exists

这是输出:

致命:[panda -> panda.herokuapp.com]:失败! => {“改变”:假, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh 'ssh -S none -o StrictHostKeyChecking=no' --rsync-path=\"sudo rsync\" --out-format='%i %n%L' \"/root/node_modules/\" \"root@panda.herokuapp.com:/home/deploy/releases/20170404121408/\"", “失败”:真,“味精”:“\r\nrsync:mkdir \"/home/deploy/releases/20170404121408/\" 失败:没有这样的文件 或目录 (2)\nrsync 错误:文件 IO(代码 11)中的错误 main.c(605) [Receiver=3.0.9]\nrsync: 连接意外关闭 (9 到目前为止收到的字节数)[发件人]\nrsync 错误:rsync 协议中的错误 io.c(605) [sender=3.0.9]\n", "rc": 12}

处的数据流(代码 12)

Ansible 版本:ansible 2.2.1.0

很明显,Rsync 命令正在尝试同步到远程服务器而不是本地主机。我可以保证路径/home/deploy/releases/20170404121408/ 存在于本地主机上,但不存在于熊猫上。我错过了什么?

【问题讨论】:

  • @techraf 是的,我做到了。这是我特别引用的一段话:# Synchronization of two paths both on the control machine - synchronize: src: some/relative/path dest: /some/absolute/path delegate_to: localhost
  • @techraf src 是否是相对路径问题 - 在我的情况下 src 和 dest 都是绝对路径。我认为这不会影响行为,但很高兴尝试一下。

标签: python deployment ansible rsync ansible-2.x


【解决方案1】:

引用the very page you referenced的相关段落:

对于synchronize 模块,“本地主机”是同步任务发起的主机,“目标主机”是同步连接到的主机。

还有:

mode(默认:push)指定同步的方向。在推送模式下,本地主机或委托是源;在拉模式下,上下文中的远程主机是源。

【讨论】:

  • 仍然无法理解同一页面上的这个特定示例:# Synchronization of two paths both on the control machine - synchronize: src: some/relative/path dest: /some/absolute/path delegate_to: localhost 这个示例没有指定模式,顶部的注释说这是从控制机器执行 rsync 的语法。我错过了什么?
  • 这个例子写的没有意义,它缺少播放正在运行的主机的信息。
  • 这是否意味着由于我似乎无法控制目标主机,所以我实际上无法在同一台控制机器之间进行 rsync 同步?我知道我可以在同一台远程机器上进行 rsync。
  • 我觉得这个例子很清楚预期的功能是什么控制机器上两条路径的同步 - 这个例子可能是错误的,但是什么地方有歧义它打算做什么?
  • 你可以,只是不能在与另一个目标对抗的比赛中。
猜你喜欢
  • 1970-01-01
  • 2021-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-16
  • 2018-07-22
  • 2014-12-02
  • 1970-01-01
相关资源
最近更新 更多