# Newbie: Am I using add\_host correctly because I don't get the result I'm expecting

**URL:** <https://forum.ansible.com/t/newbie-am-i-using-add-host-correctly-because-i-dont-get-the-result-im-expecting/28550>\
**Category:** Ansible Project\
**Created:** [September 11, 2018, 10:55am UTC](https://forum.ansible.com/t/newbie-am-i-using-add-host-correctly-because-i-dont-get-the-result-im-expecting/28550 "2018-09-11T10:55:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maria\_MacCallum](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@Maria\_MacCallum](https://forum.ansible.com/u/Maria_MacCallum)\
**Post date:** [September 11, 2018, 10:55am UTC](https://forum.ansible.com/t/newbie-am-i-using-add-host-correctly-because-i-dont-get-the-result-im-expecting/28550/1 "2018-09-11T10:55:20Z")

</div>

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 }}”

---

<div class="post-metadata">

**Author:** ![Maria\_MacCallum](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@Maria\_MacCallum](https://forum.ansible.com/u/Maria_MacCallum)\
**Post date:** [September 13, 2018, 8:26am UTC](https://forum.ansible.com/t/newbie-am-i-using-add-host-correctly-because-i-dont-get-the-result-im-expecting/28550/2 "2018-09-13T08:26:07Z")

</div>

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!!!
