2017-04-04 35 views
0

我需要rsync从控制机器到控制机器的目录(源和目标是本地主机)。我遵循指令here并在脚本中添加了delegate_to: localhost。尽管如此,synchronize指令会尝试将远程计算机用作目标并失败。Ansible Synchronize不尊重delegate_to | Rsync来自控制机器

- 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 

下面是输出:

fatal: [panda -> panda.herokuapp.com]: FAILED! => {"changed": false, "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/\" \"[email protected]:/home/deploy/releases/20170404121408/\"", "failed": true, "msg": "\r\nrsync: mkdir \"/home/deploy/releases/20170404121408/\" failed: No such file or directory (2)\nrsync error: error in file IO (code 11) at main.c(605) [Receiver=3.0.9]\nrsync: connection unexpectedly closed (9 bytes received so far) [sender]\nrsync error: error in rsync protocol data stream (code 12) at io.c(605) [sender=3.0.9]\n", "rc": 12}

Ansible版本:ansible 2.2.1.0

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

+0

@techraf是我做到了。下面是我特别引述的一段话: '''#的两条路径都在控制机器 同步 - 同步: 源:一些/相对/路径 DEST:/一些/绝对/路径 delegate_to:本地主机 '' ' – rtindru

+0

@techraf src是相对路径的问题 - 在我的情况下,src和dest都是绝对路径。我认为这不会影响行为,但我很乐意尝试。 – rtindru

回答

1

报价从the very page you referenced相关段落:

For the synchronize module, the “local host” is the host the synchronize task originates on, and the “destination host” is the host synchronize is connecting to.

另外:

mode (default: push) Specify the direction of the synchronization. In push mode the localhost or delegate is the source; In pull mode the remote host in context is the source.

+0

仍然无法理解在同一页面上该特定示例中:所述控制机 的两个路径都 '#同步 - 同步: SRC:一些/相对/路径 DEST:/一些/绝对/路径 delegate_to:本地主机' 该示例没有指定模式,顶部的注释表示这是从控制机器进行rsync的语法。我错过了什么? – rtindru

+0

这个例子在写入时没有意义,它缺少播放正在运行的主机的信息。 – techraf

+0

这是否意味着我实际上无法从同一控制机器同步rsync,因为我似乎无法控制目标主机?我明白,我可以从同一台远程机器进行rsync同步。 – rtindru