2017-04-04 49 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