# group variable in with\_items

**URL:** <https://forum.ansible.com/t/group-variable-in-with-items/24471>\
**Category:** Ansible Project\
**Created:** [May 12, 2017, 11:56am UTC](https://forum.ansible.com/t/group-variable-in-with-items/24471 "2017-05-12T11:56:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ansible\_Novice](https://avatars.discourse-cdn.com/v4/letter/a/8797f3/32.png) [@Ansible\_Novice](https://forum.ansible.com/u/Ansible_Novice)\
**Post date:** [May 12, 2017, 11:56am UTC](https://forum.ansible.com/t/group-variable-in-with-items/24471/1 "2017-05-12T11:56:07Z")

</div>

Hello,

I am new to ansible. Trying to understand a piece of ansible using debug.

- name: Evaluate oo\_all\_hosts  
add\_host:  
name: “{{ item }}”  
groups: oo\_all\_hosts  
ansible\_ssh\_user: “{{ g\_ssh\_user | default(omit) }}”  
ansible\_become: “{{ g\_sudo | default(omit) }}”  
with\_items: “{{ g\_all\_hosts | default() }}”  
changed\_when: no

I put a debug after this

- debug:  
var: oo\_all\_hosts

prints as undefined

no issues with g\_all\_hosts

Can someone help me identify the problem?

Thanks,  
SN

---

<div class="post-metadata">

**Author:** ![Listing](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@Listing](https://forum.ansible.com/u/Listing)\
**Post date:** [May 13, 2017, 8:36pm UTC](https://forum.ansible.com/t/group-variable-in-with-items/24471/2 "2017-05-13T20:36:02Z")

</div>

What happens if you add ‘register: blah’? So like this:

- name: Evaluate oo\_all\_hosts  
add\_host:  
name: “{{ item }}”  
groups: oo\_all\_hosts  
ansible\_ssh\_user: “{{ g\_ssh\_user | default(omit) }}”  
ansible\_become: “{{ g\_sudo | default(omit) }}”  
with\_items: “{{ g\_all\_hosts | default() }}”  
changed\_when: no

register: blah

The var in the debug module is expecting the variable to be previously registered with ‘register’.
