# Ansible get variable output

**URL:** <https://forum.ansible.com/t/ansible-get-variable-output/18330>\
**Category:** Ansible Project\
**Created:** [May 28, 2015, 11:30am UTC](https://forum.ansible.com/t/ansible-get-variable-output/18330 "2015-05-28T11:30:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![R\_Dikkes](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@R\_Dikkes](https://forum.ansible.com/u/R_Dikkes)\
**Post date:** [May 28, 2015, 11:30am UTC](https://forum.ansible.com/t/ansible-get-variable-output/18330/1 "2015-05-28T11:30:54Z")

</div>

Hi all,

Thank you for reading my question. I am running into this issue and hope you can help me!

What we want to do is feed a tool with ansible to automate this. We have 99% ready, however the random password generation is still a bit difficult.  
Our goal is to generate a random password per user, register this as a unique variable based on username and then use this variable to perform multiple actions such as mailing the password and creating the user with password.

We now run into the following issue:  
The stdout of a dynamic variable is lost, and we cannot find the dynamic variable name to use it in our playbook. When we call the dynamic variable in the manner we created it we get various errors.

File information:

========= task file: main.yml ============

- include\_vars: foo.yml  
tags:

- rogier

- name: Generate a random password per user  
shell: /usr/bin/openssl passwd -1 -in /dev/urandom | head -1  
with\_dict: users  
register: “{{item.username}}\_result”  
tags:

- rogier

========= end of task file ===============

========= output: =====================

TASK: [ON4\_project\_management | Generate a random password per user] \*\*\*\*\*\*\*\*\*\*\*  
changed: [m-opennebula4] =\> (item={‘key’: ‘Piet’, ‘value’: {‘username’: ‘pietu’, ‘telephone’: ‘987-654-3210’}}) =\> {“changed”: true, “cmd”: “/usr/bin/openssl passwd -1 -in /dev/urandom | head -1”, “delta”: “0:00:00.054796”, “end”: “2015-05-28 13:26:06.705414”, “item”: {“key”: “Piet”, “value”: {“telephone”: “987-654-3210”, “username”: “pietu”}}, “rc”: 0, “start”: “2015-05-28 13:26:06.650618”, “stderr”: “”, “stdout”: “$1$C2//4lrR$1/sC83CGFVXN6Ye3GafQ7.”, “warnings”: }  
changed: [m-opennebula4] =\> (item={‘key’: ‘Klaas’, ‘value’: {‘username’: ‘klaasu’, ‘telephone’: ‘123-456-7890’}}) =\> {“changed”: true, “cmd”: “/usr/bin/openssl passwd -1 -in /dev/urandom | head -1”, “delta”: “0:00:00.222003”, “end”: “2015-05-28 13:26:07.258722”, “item”: {“key”: “Klaas”, “value”: {“telephone”: “123-456-7890”, “username”: “klaasu”}}, “rc”: 0, “start”: “2015-05-28 13:26:07.036719”, “stderr”: “”, “stdout”: “$1$BfLE8IoY$qKzqpyxuXHfw.pFIHIR461”, “warnings”: }

========= end of output ================

========= start dict file: foo.yml ==========

---

<div class="post-metadata">

**Author:** ![benno\_joy](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@benno\_joy](https://forum.ansible.com/u/benno_joy)\
**Post date:** [May 28, 2015, 12:24pm UTC](https://forum.ansible.com/t/ansible-get-variable-output/18330/2 "2015-05-28T12:24:52Z")

</div>

Hi,

iirc value for register are not passed via the templating engine, maybe this should work to get the username and thier associate password.

- name: Generate a random password per user

shell: /usr/bin/openssl passwd -1 -in /dev/urandom | head -1

with\_dict: users

register: foo

- debug: msg={{ “username:” + item.item.key + “pass:” + item.stdout }}

with\_items: foo.results

---

<div class="post-metadata">

**Author:** ![R\_Dikkes](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@R\_Dikkes](https://forum.ansible.com/u/R_Dikkes)\
**Post date:** [May 28, 2015, 12:54pm UTC](https://forum.ansible.com/t/ansible-get-variable-output/18330/3 "2015-05-28T12:54:29Z")

</div>

Hey Benno,

This answer is awesome! It works!  
(We spend so many hours with nested variables and for loops and all kinds of tricks, this is short and sweet. THANKS!)

Thank you Benno.

Rogier
