DebugFactor.com | Forum

How to add host to in-memory inventory in Ansible

I don’t have enough space in my inventory and would like to add host in-memory and pass the values dynamically. Please advise.

Please use the below to add to in-memory.

- name: Create in-memory inventory
  add_host:
   name: servername.domain.com
   groups: linux_Servers

If you need to add multiple servers at a time, use loop as below

- name: Create in-memory inventory
  add_host:
   name: "{{ item }}"
   groups: linux_Servers
  loop: "{{servers}}"