# problems with add\_host

**URL:** <https://forum.ansible.com/t/problems-with-add-host/20964>\
**Category:** Ansible Project\
**Created:** [March 23, 2016, 2:54am UTC](https://forum.ansible.com/t/problems-with-add-host/20964 "2016-03-23T02:54:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glyn\_Davies](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@Glyn\_Davies](https://forum.ansible.com/u/Glyn_Davies)\
**Post date:** [March 23, 2016, 2:54am UTC](https://forum.ansible.com/t/problems-with-add-host/20964/1 "2016-03-23T02:54:02Z")

</div>

Hi Guys,

I am having some issues getting add\_host to create a dynamic inventory correctly.

Here is the relevant section from my playbook:

`

`tasks:`  
`- name: Connect to Cloud`  
`# assume RC file has already been sourced`  
`os_auth:`

`- name: launch web instances`  
`os_server:`  
`name=web0{{ item }}`  
`flavor={{ flavor }}`  
`image={{ image }}`  
`key_name={{ key_name }}`  
`state=present`  
`wait=true`  
`network={{ network }}`  
`security_groups={{ security_groups }}`  
`auto_ip=true`  
`register: newnodes`  
`with_sequence:`  
`count={{ count }}`

`# - debug:`  
`# var: newnodes`

`- name: add nodes to runtime inventory`  
`add_host:`  
`name={{ item.name }}`  
`# group=workers`  
`# ansible_host={{ item.public_v4 }}`  
`with_items:`  
`- "{{ newnodes.results.server }}"`

`

The tasks ‘Connect to Cloud’ and ‘launch web servers’ work fine.

I also ran debug on the newnodes variable and it is returning the correct data. The problem is that when I try to run the ‘add nodes to runtime inventory’ task I get the following:

` `  
[DEPRECATION WARNING]: Skipping task due to undefined Error, in the future this will be a fatal error… This feature will be removed in a future release. Deprecation warnings can be disabled by setting  
deprecation\_warnings=False in ansible.cfg.

`  
``

`

If I run the playbook with -vvvv I get no further information. I have also tried various combinations of the variable name '`newnodes.results.server' `in the with\_items section but no joy.

Anyone able to see what I have missed here?

Cheers,  
Glyn

``

---

<div class="post-metadata">

**Author:** ![Uditha\_Desilva](https://avatars.discourse-cdn.com/v4/letter/u/f475e1/32.png) [@Uditha\_Desilva](https://forum.ansible.com/u/Uditha_Desilva)\
**Post date:** [March 23, 2016, 1:42pm UTC](https://forum.ansible.com/t/problems-with-add-host/20964/2 "2016-03-23T13:42:42Z")

</div>

That isn’t how you invoke a dynamic inventory…

There’s an example of how an openstack dynamic inventory script is used on in the [Ansible.com](http://Ansible.com) docs: [http://docs.ansible.com/ansible/intro\_dynamic\_inventory.html#other-inventory-scripts](http://docs.ansible.com/ansible/intro_dynamic_inventory.html#other-inventory-scripts)

An ansible dynamic inventory script returns valid JSON that defines hosts, groups, etc. – and if it wants to return all the info for all nodes at once, it can set per-host values in a \_meta group.7

---

<div class="post-metadata">

**Author:** ![Glyn\_Davies](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@Glyn\_Davies](https://forum.ansible.com/u/Glyn_Davies)\
**Post date:** [March 23, 2016, 5:09pm UTC](https://forum.ansible.com/t/problems-with-add-host/20964/3 "2016-03-23T17:09:24Z")

</div>

Hi Uditha,

Yes I realise that is an option but what I am trying to do is use the in-memory inventory see [http://docs.ansible.com/ansible/add\_host\_module.html](http://docs.ansible.com/ansible/add_host_module.html)

This way I can have the same running playbook perform subsequent tasks on the new hosts once they are online.

Cheers,  
Glyn
