# SyntaxError with synchronize module

**URL:** <https://forum.ansible.com/t/syntaxerror-with-synchronize-module/14853>\
**Category:** Ansible Project\
**Created:** [March 25, 2014, 2:11pm UTC](https://forum.ansible.com/t/syntaxerror-with-synchronize-module/14853 "2014-03-25T14:11:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehul\_Ved](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mehul\_Ved](https://forum.ansible.com/u/Mehul_Ved)\
**Post date:** [March 25, 2014, 2:11pm UTC](https://forum.ansible.com/t/syntaxerror-with-synchronize-module/14853/1 "2014-03-25T14:11:49Z")

</div>

Hi,  
&nbsp;&nbsp;I am using ansible 1.4.4. I get SyntaxError when running synchronize plugin.

Here's the playbook entry

&nbsp;&nbsp;- name: create common folders  
&nbsp;&nbsp;&nbsp;&nbsp;synchronize: src=s dest=/etc/ssh

Here's the error that I get

failed: [play] =\> {"failed": true, "item": "", "parsed": false}  
invalid output was: File  
"/home/mehul/.ansible/tmp/ansible-1395752291.48-66351699093462/synchronize",  
line 556  
&nbsp;&nbsp;&nbsp;&nbsp;except OSError, e:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^  
SyntaxError: invalid syntax

FATAL: all hosts have already failed -- aborting

I get the same error when running synchronize module using ansible command line

$ ansible -i hosts web -m synchronize -a "src=ssh dest=/tmp/ssh"  
play | FAILED \>\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"failed": true,  
&nbsp;&nbsp;&nbsp;&nbsp;"msg": " File  
\"/home/mehul/.ansible/tmp/ansible-1395752376.63-279538261866126/synchronize\",  
line 556\n except OSError, e:\n ^\nSyntaxError:  
invalid syntax\n",  
&nbsp;&nbsp;&nbsp;&nbsp;"parsed": false  
}

Ansible is installed in virtualenv

$ which python  
/home/mehul/apps/lsdeploy/venv/bin/python

$ python --version  
Python 2.7.6

$ which ansible  
/home/mehul/apps/lsdeploy/venv/bin/ansible

$ ansible --version  
ansible 1.4.4

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 25, 2014, 2:13pm UTC](https://forum.ansible.com/t/syntaxerror-with-synchronize-module/14853/2 "2014-03-25T14:13:47Z")

</div>

Hmm, that’s unexpected.

Since the latest stable release is 1.5.3, can you see if that happens there, and if so, file a github ticket at [github.com/ansible/ansible](http://github.com/ansible/ansible)?

The synchronize module received a lot of improvements in the last few months so there is a decent chance you’ll be good to go.

Thanks!

---

<div class="post-metadata">

**Author:** ![Ernest0x](https://avatars.discourse-cdn.com/v4/letter/e/ed655f/32.png) [@Ernest0x](https://forum.ansible.com/u/Ernest0x)\
**Post date:** [March 25, 2014, 2:30pm UTC](https://forum.ansible.com/t/syntaxerror-with-synchronize-module/14853/3 "2014-03-25T14:30:55Z")

</div>

The syntax error you get could be caused by a python 3 interpreter being  
used at the target machine instead of python 2. This is a common error  
when running ansible on target machines running Archlinux because the  
default python interpreter (at /usr/bin/python) on Arch is actually the  
python3 interpreter. In these cases you should set the  
"ansible\_python\_interpreter" variable for the affected hosts to the  
correct path ("/usr/bin/python2" for archlinux).

---

<div class="post-metadata">

**Author:** ![Mehul\_Ved](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mehul\_Ved](https://forum.ansible.com/u/Mehul_Ved)\
**Post date:** [March 25, 2014, 2:42pm UTC](https://forum.ansible.com/t/syntaxerror-with-synchronize-module/14853/4 "2014-03-25T14:42:29Z")

</div>

That did fix the problem. I was assuming that isn't required when you  
install using virtualenv. Everything else has been working fine so  
far, this was the first thing I ran into an issue with while using  
ansible from virtualenv. Should this be considered a bug? If so, I'll  
open a new ticket on github.

---

<div class="post-metadata">

**Author:** ![Ernest0x](https://avatars.discourse-cdn.com/v4/letter/e/ed655f/32.png) [@Ernest0x](https://forum.ansible.com/u/Ernest0x)\
**Post date:** [March 25, 2014, 3:11pm UTC](https://forum.ansible.com/t/syntaxerror-with-synchronize-module/14853/5 "2014-03-25T15:11:21Z")

</div>

It is not a bug. It is just that some hosts need to be configured so  
that ansible uses the python2 interpreter when running on them. Also,  
running from inside a virtualenv has nothing to do with this. Running  
from outside (not in a virtualenv) would cause the same error. It is an  
error caused on remote host (controlled), not on local host (controller).

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [March 25, 2014, 3:12pm UTC](https://forum.ansible.com/t/syntaxerror-with-synchronize-module/14853/6 "2014-03-25T15:12:00Z")

</div>

Does the remote host have ansible\_python\_interpreter set in your inventory?

---

<div class="post-metadata">

**Author:** ![Mehul\_Ved](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mehul\_Ved](https://forum.ansible.com/u/Mehul_Ved)\
**Post date:** [March 26, 2014, 10:10am UTC](https://forum.ansible.com/t/syntaxerror-with-synchronize-module/14853/7 "2014-03-26T10:10:13Z")

</div>

Probably I'm failing to understand the internal working and should  
spend more time understanding ansible. I was assuming that when  
running inside virtualenv, it would use python installation inside  
virtualenv only but that doesn't seem to be the case with synchronize  
module. I should probably understand how it works internally to  
understand why this happens.

---

<div class="post-metadata">

**Author:** ![Mehul\_Ved](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mehul\_Ved](https://forum.ansible.com/u/Mehul_Ved)\
**Post date:** [March 26, 2014, 10:10am UTC](https://forum.ansible.com/t/syntaxerror-with-synchronize-module/14853/8 "2014-03-26T10:10:41Z")

</div>

No it didn't earlier.

---

<div class="post-metadata">

**Author:** ![Ernest0x](https://avatars.discourse-cdn.com/v4/letter/e/ed655f/32.png) [@Ernest0x](https://forum.ansible.com/u/Ernest0x)\
**Post date:** [March 26, 2014, 3:41pm UTC](https://forum.ansible.com/t/syntaxerror-with-synchronize-module/14853/9 "2014-03-26T15:41:12Z")

</div>

Ansible runs first on the local machine (controller), then opens an ssh  
connection to the remote machine (target), copies itself and needed  
modules to the remote machine and invokes itself on the remote machine.  
So, eventually you will have \_two\_ processes of ansible: one runs on  
local machine and the other runs on the remote machine. If you happen to  
have installed ansible on the local machine inside a virtual environment  
and you have enabled that virtualenv, then the process running on the  
local machine will be running in the context of that virtualenv. On the  
other hand, the process that is running on the remote machine will have  
been invoked with the python interpreter configured with  
ansible\_python\_interpreter (which defaults to '/usr/bin/python').
