SyntaxError with synchronize module

275 views
Skip to first unread message

Mehul Ved

unread,
Mar 25, 2014, 10:11:49 AM3/25/14
to ansible...@googlegroups.com
Hi,
I am using ansible 1.4.4. I get SyntaxError when running synchronize plugin.

Here's the playbook entry

- name: create common folders
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
except OSError, e:
^
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 >> {
"failed": true,
"msg": " File
\"/home/mehul/.ansible/tmp/ansible-1395752376.63-279538261866126/synchronize\",
line 556\n except OSError, e:\n ^\nSyntaxError:
invalid syntax\n",
"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

Michael DeHaan

unread,
Mar 25, 2014, 10:13:47 AM3/25/14
to ansible...@googlegroups.com
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?

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!





--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, 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/CADTL0ob_XLGuUXVhF89kRqXqkm%3DR2u986PasTeF1kqmQkcByww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Petros Moisiadis

unread,
Mar 25, 2014, 10:30:55 AM3/25/14
to ansible...@googlegroups.com
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).

Mehul Ved

unread,
Mar 25, 2014, 10:42:29 AM3/25/14
to ansible...@googlegroups.com
On Tue, Mar 25, 2014 at 8:00 PM, Petros Moisiadis <erne...@yahoo.gr> wrote:
> 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).

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.


--
With Regards,
Mehul Ved

Petros Moisiadis

unread,
Mar 25, 2014, 11:11:21 AM3/25/14
to ansible...@googlegroups.com
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).

James Tanner

unread,
Mar 25, 2014, 11:12:00 AM3/25/14
to ansible...@googlegroups.com
Does the remote host have ansible_python_interpreter set in your inventory?
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, 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/CADTL0oa_a8fK4GkB-yeoN5bDM1SZxpzHruJsyUPNU2t4Of8KEw%40mail.gmail.com.

Mehul Ved

unread,
Mar 26, 2014, 6:10:13 AM3/26/14
to ansible...@googlegroups.com
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.
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, 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/53319C99.4000802%40yahoo.gr.
> For more options, visit https://groups.google.com/d/optout.



Mehul Ved

unread,
Mar 26, 2014, 6:10:41 AM3/26/14
to ansible...@googlegroups.com
No it didn't earlier.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/384C2C57-0262-44F5-9499-E8D7A6E19D72%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.



Petros Moisiadis

unread,
Mar 26, 2014, 11:41:12 AM3/26/14
to ansible...@googlegroups.com
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').
Reply all
Reply to author
Forward
0 new messages