Newbie: Am I using add_host correctly because I don't get the result I'm expecting

I’ve tried pre-defining an empty group and not defining, neither seems to work, the group seems to remain empty when I try to use it, I’m sure I’m missing something vital out.

This is an extract:

  • hosts: all-t4

need serial 1 to be able t use add_host more than once

serial: 1
remote_user: XXXX
tasks:

  • name: gather ldom info
    shell: /usr/sbin/ldm ls -p |awk -F’=’ ‘/active/ {print $2}’ | awk -F’|’ ‘{print $1}’ |grep -v primary | sed -e ‘s/iodomain/{{ inventory_hostname }}-io/’
    register: output
  • name: add ldom to in-mem inventory
    add_host:
    name: “{{ item }}”
    groups: ldoms
    with_items: “{{ output.stdout_lines }}”
  • debug:
    msg: “{{ group_names }}”
    with_items: “{{ output.stdout_lines }}”
  • hosts: all
    tasks:
  • debug: var=“{{ group_names }}”

SOLVED: So I tried extracting the code that I’m having trouble with into a separate playbook and then everything started to work, I then removed all the debug messages, and slowly added in the rest of what I needed the playbook to do and now it all works totally fine!!!