# task to  assign result of a lookup to a registered variable

**URL:** <https://forum.ansible.com/t/task-to-assign-result-of-a-lookup-to-a-registered-variable/33806>\
**Category:** Ansible Project\
**Created:** [September 14, 2020, 2:30pm UTC](https://forum.ansible.com/t/task-to-assign-result-of-a-lookup-to-a-registered-variable/33806 "2020-09-14T14:30:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonin](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@Jonin](https://forum.ansible.com/u/Jonin)\
**Post date:** [September 14, 2020, 2:30pm UTC](https://forum.ansible.com/t/task-to-assign-result-of-a-lookup-to-a-registered-variable/33806/1 "2020-09-14T14:30:55Z")

</div>

Hi,

Is there a way to assign the value of a lookup (in this case a password) to a variable and register it so that the registered variable can then be used in different tasks of play without having to call the lookup itself multiple times?

The closest I have got is using the debug module where I thought I could maybe register the msg. It is not working though as register is not a valid option for debug I think.

- debug:  
msg: “{{ lookup(‘vault’,vaultLookupString) }}”

Ideally I would like a named task like below but this does not work.

- name: Obtain password  
PASSWROD= “{{ lookup(‘vault’,vaultLookupString) }}”  
register: PASSWORD

- name: Use registered PASSWORD from previous task to do stuff  
copy:  
dest:  
content:  
DB\_USER=dbuser  
DB\_PASSWORD= PASSWORD

- name: Use registered PASSWORD again to do more stuff  
…

Currently I am having to do this which I want to avoid as more tasks rely on the password.

- name: Use registered PASSWORD from previous task to do stuff  
copy:  
dest:  
content:  
DB\_USER=dbuser  
DB\_PASSWORD= “{{ lookup(‘vault’,vaultLookupString) }}”

Any help much appreciated.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [September 14, 2020, 3:58pm UTC](https://forum.ansible.com/t/task-to-assign-result-of-a-lookup-to-a-registered-variable/33806/2 "2020-09-14T15:58:32Z")

</div>

[https://docs.ansible.com/ansible/latest/modules/set\_fact\_module.html](https://docs.ansible.com/ansible/latest/modules/set_fact_module.html)

---

<div class="post-metadata">

**Author:** ![Jonin](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@Jonin](https://forum.ansible.com/u/Jonin)\
**Post date:** [September 14, 2020, 5:55pm UTC](https://forum.ansible.com/t/task-to-assign-result-of-a-lookup-to-a-registered-variable/33806/3 "2020-09-14T17:55:51Z")

</div>

Thank you. That’s done the job. Exactly what I was after.
