Dynamic Inventory """"""""""""""""" Dynamic inventory scripts ========================= * Ansible supports other inventory sources via an external inventory system * many inventory scripts are available in the github repo. Here are some examples: * zabbix * vmware * spacewalk * openstack * nagios * gce * ec2 * azure * cobbler * you can write your own inventory script in **any language** * return JSON in the right format * fill up the the proper arguments * reload inventory during a playbook run .. code-block:: yaml - name: reload inventory, useful with dynamic inventories when play makes changes to the existing hosts cloud_guest: # this is fake module name: newhost state: present - name: Refresh inventory to ensure new instaces exist in inventory meta: refresh_inventory .. hint:: Checkout the **tuning** tipps in the Ansible documentation. How to use dynamic inventory ---------------------------- * Ansible reads the configured ``inventory`` path * if the file is executable, Ansible will execute it * as example download a dynmic inventory script e.g ec2.py * change the permissions -> ``chmod +x`` .. hint:: It's possible to set a folder as inventroy. And there you can mix static & dynamic inventories. * a mixed inventory example .. code-block:: yaml inventory/ ├── [-rwxr-xr-x] ec2.py ├── [-rw-r--r--] static └── [-rwxr-xr-x] zabbix.py Links ----- * http://docs.ansible.com/ansible/intro_dynamic_inventory.html * https://github.com/ansible/ansible/tree/devel/contrib/inventory * http://docs.ansible.com/ansible/developing_inventory.html * http://docs.ansible.com/ansible/developing_inventory.html#tuning-the-external-inventory-script