Using dynamic inventory
As we have established in previous chapters, managing a text-based inventory can be a pain. There are chances that a manually managed inventory can consist of stale data that can impact our applications. Ansible provides dynamic inventory to address this.
Ansible's GitHub repository has scripts for various infrastructure providers, including a script for DigitalOcean (https://github.com/ansible/ansible/blob/devel/contrib/inventory/digital_ocean.py).
How to do it…
- We need to download this script and configure it to use our credentials:
$ curl https://github.com/ansible/ansible/raw/devel/contrib/inventory/digital_ocean.py > digital_ocean.py $ chmod +x digital_ocean.py $ curl https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/digital_ocean.ini > digital_ocean.ini
- We need to append the following line in the
digital_ocean.ini
for authentication:
api_token = 5fcd456fb9f5hg5f29a17df55678j4fd4ecbdfghjkf4c215fghjbaa39bah7tc47m
- Let's test our inventory...