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


On Thursday, May 28, 2015 at 2:24:56 PM UTC+2, benno joy wrote:
>
> 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
>
>
>
>
> On Thu, May 28, 2015 at 5:00 PM, R. Dikkes <[email protected] 
> <javascript:>> wrote:
>
>> 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 ==========
>> --- 
>> users:
>>   Klaas:
>>     username: klaasu
>>     telephone: 123-456-7890
>>   Piet:
>>     username: pietu
>>     telephone: 987-654-3210
>> ===================================
>>
>>
>> Do you have any suggestion how we can be able to use this dynamic 
>> variable.stdout?
>>
>> -- 
>> 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 [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/3e1093ae-8c97-4de6-8292-1cbbe3610f32%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/3e1093ae-8c97-4de6-8292-1cbbe3610f32%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/61b2e8fc-4ad7-4f27-9387-c1f633a4a006%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to