# synchronize module ignores destination host

**URL:** <https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301>\
**Category:** Ansible Project\
**Created:** [August 14, 2013, 11:32am UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301 "2013-08-14T11:32:58Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nuno\_Taborda](https://avatars.discourse-cdn.com/v4/letter/n/ea5d25/32.png) [@Nuno\_Taborda](https://forum.ansible.com/u/Nuno_Taborda)\
**Post date:** [August 14, 2013, 11:32am UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/1 "2013-08-14T11:32:58Z")

</div>

Hey guys,

I was looking forward for proper rsync wrapper, so I’m very happy to finally see synchronize module in tree. Currently ansible-doc synchronize sheds some light on its proper usage, but apparently not enough to solve the problem I’m experiencing. My problematic task is the following:

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [August 14, 2013, 7:25pm UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/2 "2013-08-14T19:25:04Z")

</div>

A quick check confirms this:

$ ansible -i [antares.ginsys.net](http://antares.ginsys.net), all -m synchronize -a “src=~/src/ansible/ dest=~/tmp/” -C -vvv  
\<127.0.0.1\> ESTABLISH CONNECTION FOR USER: serge  
\<127.0.0.1\> EXEC [‘ssh’, ‘-tt’, ‘-q’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/tmp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘Port=22’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘ConnectTimeout=10’, ‘ **127.0.0.1** ’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-1376508120.59-146532073015922 && chmod a+rx $HOME/.ansible/tmp/ansible-1376508120.59-146532073015922 && echo $HOME/.ansible/tmp/ansible-1376508120.59-146532073015922’”]  
[antares.ginsys.net](http://antares.ginsys.net) | FAILED =\> Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in “/tmp”. Failed command was: mkdir -p $HOME/.ansible/tmp/ansible-1376508120.59-146532073015922 && chmod a+rx $HOME/.ansible/tmp/ansible-1376508120.59-146532073015922 && echo $HOME/.ansible/tmp/ansible-1376508120.59-146532073015922, exited with result 255

It connects to localhost instead of the remote server.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [August 14, 2013, 7:37pm UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/3 "2013-08-14T19:37:46Z")

</div>

Correction:

IIRC, the synchronize action plugin will deploy the module locally, then issue an rsync to the remote server. So that localhost connection is in fact correct. (though I don’t understand why this should happen that way, instead of running that directly from the action plugin?)

But still, something still issues a problem. -m ping works flawlessly.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 14, 2013, 9:44pm UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/4 "2013-08-14T21:44:08Z")

</div>

Hmm, this didn’t happen for me.

Tim, seeing this was your addition, do you have time to investigate?

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [August 16, 2013, 3:10pm UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/5 "2013-08-16T15:10:28Z")

</div>

It’s not happening to me either. I’ve been overloaded this week because I’m on vacation next week that I’m not going to have a chance to investigate.

From the limited info I can see the synchronize module isn’t even running leading me to believe its something in the action module.

My guess is that some path is getting generated and perhaps created before the new setup (init) method can be called to override the delegate to the localhost. To check I’d turn off temp file clean up and look at the path it says is failing on for clues.

To Serge’s question – remote to remote mirroring. Reread the pull request thread you and I had over this if you need more detail.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 16, 2013, 3:46pm UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/6 "2013-08-16T15:46:40Z")

</div>

Ok so I need to remove this from source control and the docs until it’s operational then, as we’re getting close to ship time.

I’m happy to take this when complete.

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [August 17, 2013, 2:00am UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/7 "2013-08-17T02:00:33Z")

</div>

I'm not opposed to someone else working on this.

Besides it sounds like the bug is in the core. The synchronize module is just exposing it.

\<tim/\>

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 17, 2013, 2:25am UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/8 "2013-08-17T02:25:19Z")

</div>

If the bug is in core and nothing else exposes it, is it a bug? 🙂

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [August 19, 2013, 11:23pm UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/9 "2013-08-19T23:23:57Z")

</div>

I don’t find that answer amusing Michael.

I cleaned out my branch since my work was in core. I’ve spent too much time on this already and I’m in no mood to dig my work out to resolve whatever issue the core has.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 22, 2013, 2:21am UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/10 "2013-08-22T02:21:25Z")

</div>

What I’m saying here is that you were trying to get a way to control the local host forcing in the synchronize module, and there isn’t as far as I understand it another usage of this in core.

Thus it’s more of a supporting feature that isn’t there needed to develop the module rather than a problem affecting other modules in Ansible.

That is, the issue is made manifest by the attempt at trying to make it do something it doesn’t do, but it’s at a code level that doesn’t affect any other module.

Ergo, it’s something you need to do more easily and don’t have a way maybe, but not a bug in core.

---

<div class="post-metadata">

**Author:** ![Nuno\_Taborda](https://avatars.discourse-cdn.com/v4/letter/n/ea5d25/32.png) [@Nuno\_Taborda](https://forum.ansible.com/u/Nuno_Taborda)\
**Post date:** [August 22, 2013, 2:50pm UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/11 "2013-08-22T14:50:33Z")

</div>

If that is the case it is as if Tim had to work around an incomplete API to implement this module. Will the core be improved to make this easier and more predictable for other developers?

Also, what’s the future plan of this module? As it is now, there’s a considerable amount of work nobody can benefit from just laying there.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 22, 2013, 9:37pm UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/12 "2013-08-22T21:37:08Z")

</div>

Tim could have submitted a code change to the API, but we’re not really talking about an API, we’re talking about internals.

Easy project for someone to take up I’d think.

---

<div class="post-metadata">

**Author:** ![Smoothify](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@Smoothify](https://forum.ansible.com/u/Smoothify)\
**Post date:** [August 26, 2013, 9:53pm UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/13 "2013-08-26T21:53:55Z")

</div>

I think I have this working a bit better now, the cause of this problem, is rather simple as it turns out. I have a few other minor changes i would like for this module to make it function how one would expect.

Now that this is outside of the devel branch, How is it best to create a pull request - one squashed commit with the original work + my changes, or a pull request containing multiple commits?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 27, 2013, 1:39am UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/14 "2013-08-27T01:39:05Z")

</div>

Great!

Multiple commits is ok.

It would be nice to preserve TIm’s authorship for his commits, which would be lost in the squash merge.

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [August 29, 2013, 9:06pm UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/15 "2013-08-29T21:06:01Z")

</div>

Haven’t seen a patch or pull request on this on github for this. Regardless I met Michael last night in NYC at the meetup at Gawker and mentioned what I found looking at the code. Unfortunately I don’t have the bandwidth to figure out how to reproduce the error or test these theories right now, so I’m putting them out there in the eventual someone is so motivated to pick up where I’m leaving off for now.

Looking again this morning I’m not so sure I had pinpointed things going wrong. I was thinking that by the time the setup hook in the synchronize module fires to override the delegate with local host a lot of things about the original host have been put in the inject data. My original thinking was that the place where the override happens needed to preceed setting up inject.

Note sure about that though because the delegate\_to logic in runner/ **init**.py does try to revise all the inject data from the original to the delegate. Where it might be failing in the the try block starting around line 578. If something goes wrong there that is specific to Ansible (I’m looking at the template.template() call a few lines later) it quitely handles that exception by just setting the host and post. The user, pass, key file, connection and interpreter are not. So after the setting the inventory host’s ssh variables, if setting up the delegate throws the right type of exception some values belonging to original could be sticking around to confuse what follows.

Just thinking outloud.

---

<div class="post-metadata">

**Author:** ![Smoothify](https://avatars.discourse-cdn.com/v4/letter/s/6a8cbe/32.png) [@Smoothify](https://forum.ansible.com/u/Smoothify)\
**Post date:** [September 4, 2013, 12:49pm UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/16 "2013-09-04T12:49:22Z")

</div>

Sorry for the delay on this, but I have now created a pull request with my fixes and improvements.

[https://github.com/ansible/ansible/pull/4019](https://github.com/ansible/ansible/pull/4019)

Please do all test it out and let me know how it works for you.

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [September 5, 2013, 9:29pm UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/17 "2013-09-05T21:29:45Z")

</div>

I went over this for anyone that is interested in providing feedback.

[https://github.com/ansible/ansible/pull/4019](https://github.com/ansible/ansible/pull/4019)  
[https://github.com/smoothify/ansible/commit/b28297a3d4f1c76e5c08f574f32d6cd938986723](https://github.com/smoothify/ansible/commit/b28297a3d4f1c76e5c08f574f32d6cd938986723)

A bit off-topic that reviewing this code reminded me of something I’ve been meaning to ask.

A lot of modules are dependent on a command line. sychronize is an example of that. Shouldn’t we have a standard means of specifying or overriding the path to a bin/exe? Ansible implements such functionality for any interpreter such as ansible\_python\_interpreter and it also supports one for sudo\_exe in the configs. But’s missing is a mechanism for me to specify that rsync is /found/in/some/weird/path/our/sysadmin/forces/us/to/use/rsync.

Know that was an issue for me I implemented an rsync\_path option. I 'm thinking this sort of thing would be beneficial to any module that depends on a system tool.

Thoughts?

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [September 5, 2013, 11:36pm UTC](https://forum.ansible.com/t/synchronize-module-ignores-destination-host/13301/18 "2013-09-05T23:36:38Z")

</div>

This makes a lot of sense to me.
