See
https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#registering-variables-with-a-loop

On Fri, Jun 25, 2021 at 1:59 PM [email protected] <[email protected]>
wrote:

> Thanks!  I feel stupid.  That worked.  However, now I'm getting an error
> in printing out the user's email address.  I'm registering a variable
> called email, and when I do the debug message, I get an error that says
> that stdout isn't defined.  if I just print out the variable 'email' I see
> stdout present.  I'm just doing this so i can hopefully use the email later
> on.
>
> Thanks,
> Harry
>
> On Friday, June 25, 2021 at 2:49:48 PM UTC-4 Matt Martz wrote:
>
>> Instead of:
>>
>>   loop:
>>     - "{{ users }}"
>>
>> You want:
>>
>>   loop: "{{ users }}"
>>
>> Otherwise, you are creating a list in YAML with the value of users as the
>> single element.
>>
>> On Fri, Jun 25, 2021 at 1:44 PM [email protected] <[email protected]>
>> wrote:
>>
>>> I'm trying to look through a loop of users to get their email addresses
>>> from an IPA server.  When I run it, I get an error stating that "name" is
>>> an undefined variable.  Can anyone see what I'm doing wrong?
>>>
>>> ---
>>> - hosts: localhost
>>>   become: yes
>>>   become_method: sudo
>>>   gather_facts: no
>>>
>>>   vars_files:
>>>     - /etc/ansible/vault.yml
>>>
>>>   vars:
>>>     - users:
>>>       - { name: "user1 }
>>>       - { name: "user2" }
>>>
>>>   tasks:
>>>
>>>   - name: Get User's Email Address
>>>     shell: "set -o pipefail && /bin/ipa user-show {{ item.name }} --all
>>> --raw | grep mail: | awk '{print $2}'"
>>>     register: email
>>>     loop:
>>>     - "{{ users }}"
>>>
>>>   - name: Print email
>>>     debug:
>>>       msg: "{{ email.stdout }}"
>>>
>>> The error states  "The task includes an option with an undefined
>>> variable.  The error was: 'list object' has no attribute 'name'".
>>>
>>> Thanks,
>>> Harry
>>>
>>> --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/ac83150f-a884-4a72-8024-330f5ce8b0fen%40googlegroups.com
>>> <https://groups.google.com/d/msgid/ansible-project/ac83150f-a884-4a72-8024-330f5ce8b0fen%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> --
>> Matt Martz
>> @sivel
>> sivel.net
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/fb99b2af-08b2-4741-94a2-aed71d86ab21n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/fb99b2af-08b2-4741-94a2-aed71d86ab21n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Matt Martz
@sivel
sivel.net

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8N0v-51PPi9w-mMUtqQT8m8WXmGsNfcXoYOcrbDBM8mxpVXg%40mail.gmail.com.

Reply via email to