# Register variable locally and use on remote host

**URL:** <https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419>\
**Category:** Ansible Project\
**Created:** [June 5, 2015, 10:22pm UTC](https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419 "2015-06-05T22:22:53Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Pires](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@David\_Pires](https://forum.ansible.com/u/David_Pires)\
**Post date:** [June 5, 2015, 10:22pm UTC](https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419/1 "2015-06-05T22:22:53Z")

</div>

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;

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 5, 2015, 11:32pm UTC](https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419/2 "2015-06-05T23:32:05Z")

</div>



---

<div class="post-metadata">

**Author:** ![David\_Pires](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@David\_Pires](https://forum.ansible.com/u/David_Pires)\
**Post date:** [June 6, 2015, 12:26am UTC](https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419/3 "2015-06-06T00:26:10Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 6, 2015, 12:31am UTC](https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419/4 "2015-06-06T00:31:02Z")

</div>

Do you have boto installed on your machine?

---

<div class="post-metadata">

**Author:** ![David\_Pires](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@David\_Pires](https://forum.ansible.com/u/David_Pires)\
**Post date:** [June 6, 2015, 12:33am UTC](https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419/5 "2015-06-06T00:33:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 6, 2015, 1:11am UTC](https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419/6 "2015-06-06T01:11:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![David\_Pires](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@David\_Pires](https://forum.ansible.com/u/David_Pires)\
**Post date:** [June 6, 2015, 2:07am UTC](https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419/7 "2015-06-06T02:07:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 6, 2015, 2:18am UTC](https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419/8 "2015-06-06T02:18:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![David\_Pires](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@David\_Pires](https://forum.ansible.com/u/David_Pires)\
**Post date:** [June 6, 2015, 2:26am UTC](https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419/9 "2015-06-06T02:26:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 6, 2015, 3:01am UTC](https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419/10 "2015-06-06T03:01:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![David\_Pires](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@David\_Pires](https://forum.ansible.com/u/David_Pires)\
**Post date:** [June 6, 2015, 3:11am UTC](https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419/11 "2015-06-06T03:11:23Z")

</div>

> * * *
> 
> - 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.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 6, 2015, 3:26am UTC](https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419/12 "2015-06-06T03:26:04Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![David\_Pires](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@David\_Pires](https://forum.ansible.com/u/David_Pires)\
**Post date:** [June 6, 2015, 3:53am UTC](https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419/13 "2015-06-06T03:53:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Martin2](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@Martin2](https://forum.ansible.com/u/Martin2)\
**Post date:** [June 6, 2015, 10:44am UTC](https://forum.ansible.com/t/register-variable-locally-and-use-on-remote-host/18419/14 "2015-06-06T10:44:19Z")

</div>

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
