group variable in with_items

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

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’.