synchronize between two remote servers: you can pull but you cannot push?

43 views
Skip to first unread message

Joe Louthan

unread,
May 2, 2016, 10:29:22 AM5/2/16
to Ansible Project
So pulling in synchronize between two remote servers works like a champ:
---
- hosts: web14
  remote_user: jlouthan
  tasks:
      - name: Get current timestamp
        local_action: command bash -c 'date +%Y-%m-%d.%H%M'
        register: timestamp
        run_once: true

      - name: Get current datestamp
        local_action: command bash -c 'date +%Y-%m-%d'
        register: datestamp
        run_once: true

      - name: Create test file
        file: path=/home/jlouthan/testing{{ timestamp.stdout }} state=touch

      - name: List the file recently created
        shell: ls -la /home/jlouthan | grep {{ datestamp.stdout }}
        register: touchtest

      - debug: var=touchtest.stdout_lines

      - pause: prompt='Note the name of the file'

      - name: Pull test file from web16 to web14
        synchronize: mode=pull src=/home/jlouthan/testing{{ timestamp.stdout }} dest=/home/jlouthan/
        delegate_to: web16

      - name: List test files from today
        shell: ls -la /home/jlouthan | grep {{ datestamp.stdout }}
        delegate_to: web16
        register: destcheck

      - debug: var=destcheck.stdout_lines

      - pause: prompt='Check dest test files'



However, pushing from one remote server to another does not work:
$ cat test-push-files.yml
---
- hosts: web16
  remote_user: jlouthan
  tasks:
      - name: Get current timestamp
        local_action: command bash -c 'date +%Y-%m-%d.%H%M'
        register: timestamp

      - name: Get current datestamp
        local_action: command bash -c 'date +%Y-%m-%d'
        register: datestamp

      - name: Create test file
        file: path=/home/jlouthan/testing{{ timestamp.stdout }} state=touch
        delegate_to: web14

      - name: List the file recently created
        shell: ls -la /home/jlouthan | grep {{ datestamp.stdout }}
        delegate_to: web14
        register: touchtest

      - debug: var=touchtest.stdout_lines

      - pause: prompt='Note the name of the file'

      - name: Pull test file from web14 to web16
        synchronize: src=/home/jlouthan/testing{{ timestamp.stdout }} dest=/home/jlouthan
        delegate_to: web14

PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [web16]

TASK [Get current timestamp] ***************************************************
changed: [web16 -> localhost]

TASK [Get current datestamp] ***************************************************
changed: [web16 -> localhost]

TASK [Create test file] ********************************************************
changed: [web16 -> web14]

TASK [List the file recently created] ******************************************
changed: [web16 -> web14]

TASK [debug] *******************************************************************
ok: [web16] => {
    "touchtest.stdout_lines": [
        "-rw-r--r--  1 jlouthan jlouthan        0 May  2 14:43 testing2016-05-02.0843",
        "-rw-r--r--  1 jlouthan jlouthan        0 May  2 14:45 testing2016-05-02.0845",
        "-rw-r--r--  1 jlouthan jlouthan        0 May  2 14:46 testing2016-05-02.0846",
        "-rw-r--r--  1 jlouthan jlouthan        0 May  2 14:56 testing2016-05-02.0856",
        "-rw-r--r--  1 jlouthan jlouthan        0 May  2 15:06 testing2016-05-02.0906",
        "-rw-r--r--  1 jlouthan jlouthan        0 May  2 15:14 testing2016-05-02.0914",
        "-rw-r--r--  1 jlouthan jlouthan        0 May  2 15:18 testing2016-05-02.0918",
        "-rw-r--r--  1 jlouthan jlouthan        0 May  2 15:19 testing2016-05-02.0919",
        "-rw-r--r--  1 jlouthan jlouthan        0 May  2 15:25 testing2016-05-02.0925"
    ]
}

TASK [pause] *******************************************************************
[pause]
Note the name of the file:
ok: [web16]

TASK [Pull test file from web14 to web16] **************************************
fatal: [web16 -> web14]: FAILED! => {"changed": false, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh '/usr/bin/ssh  -S none -o StrictHostKeyChecking=no' --out-format='<<CHANGED>>%i %n%L' \"/home/jlouthan/testing2016-05-02.0925\" \"web16:/home/jlouthan\"", "failed": true, "msg": "rsync: --out-format=<<CHANGED>>%i %n%L: unknown option\nrsync error: syntax or usage error (code 1) at main.c(1231) [client=2.6.8]\n", "rc": 1}

NO MORE HOSTS LEFT *************************************************************
to retry, use: --limit @test-push-files.retry

PLAY RECAP *********************************************************************
web16                      : ok=7    changed=4    unreachable=0    failed=1


I tried following the examples using rsync within synchronize:

... and that doesn't seem to work for me.

I guess what I am asking is how do you rsync pushing from one remote server to another (as oppose to pulling which I can successfully do).

Johannes Kastl

unread,
May 3, 2016, 3:21:20 AM5/3/16
to ansible...@googlegroups.com
On 02.05.16 16:29 Joe Louthan wrote:

> I guess what I am asking is how do you rsync pushing from one remote server
> to another (as oppose to pulling which I can successfully do).

I would call rsync via shell/command rather than use the synchronize
module.

Johannes



signature.asc

Joseph Louthan

unread,
May 3, 2016, 9:41:53 AM5/3/16
to ansible...@googlegroups.com
Good enough. Thank you.



Sincerely,

Joe Louthan




--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/R99b0yWdp88/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5728280B.6040809%40ojkastl.de.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages