Register variable locally and use on remote host

I am trying to use the route53 module in a playbook.

If i install boto and add credentials the play works (reading a record and registering it), however I want to know if I can do this locally (where boto is installed) and have that registered variable available on remote hosts.

Example playbook;

I am getting the same error: “failed=True msg='boto required for this module”

My inventory file is as follows:

[localhost]
localhost ansible_python_interpreter=PATH

[test]
IP

And my playbook:

Do you have boto installed on your machine?

boto is installed on the ansible machine, not the remote host

then if you added connection: local to the task, it should be
executing locally and picking up boto

I think I have found the issue, I’m running ansible in a virtualenv.

I have “ansible_python_interpreter” set for localhost, this doesn’t work for remote hosts.

When I run ansible with boto available globally, it works. Is there a solution to get ansible to find dependencies for remote hosts?

I don't think I'm parsing what you are saying correctly. I thought you
were running the task that required boto locally.

ansible_python_interpreter is what you use to direct ansible to the
correct python with the correct dependencies, it only applies for
those hosts for which you set it.

I am trying to run the route53 module locally, register its output and use that variable in a task for a remote host.

This works if i have boto installed globally, using connection: local. It does not work when using inside a virtualenv.

I reproduced this in a virtual machine with boto available globally, and it works. On my mac laptop, I am using boto/ansible inside a virtualenv and this is where boto can not be found for a remote host.

On my local machine, when running on a localhost (with python_interpreter set), it does work and boto is found, however the variable isn’t available on the remote host.

I'm confused, what you are stating seems to contradict itself.


  • hosts: remote_host
    pre_tasks:
  • name: Read host
    connection: local
    route53:
    command: get
    zone: ZONE
    record: RECORD
    type: A
    register: host_record
    roles:
  • test

When boto/ansible is available globally, this playbook works as expected, it registers the variable and can be used on a remote host.

This does not work when boto/ansible is being used inside a virtualenv. Boto can not be found.

What seems to be the issue, is ansible is using the global python version (which doesn’t have boto) when using remote hosts.

When inside the virtualenv and setting python_interpreter for localhost, these tasks work on localhost.

So set ansible_python_interpreter to the correct Python binary for the virtualenv on the remote host.

Also, you can execute tasks on localhost and then reference it from another host:

http://docs.ansible.com/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts

Or use local_action which will delegate to localhost, but register the car to the remote host.

Setting the interpreter for the remote host would require boto being installed on the remote host, which isn’t what I’m after.

Setting the variable on localhost and accessing it remotely using hostvars does work, however, the real issue is how ansible can’t seem to find boto when its run inside a virtualenv for a remote host task.

Boto is required on the host it runs on.

There is no way to execute boto specific things on “test” when it is only installed on local host.

What you can do is something like collect information on “test” then run boto stuff on “localhost”.

/martin