Company
Date Published
Author
Joey Stout
Word count
2151
Language
English
Hacker News points
None

Summary

Ansible can connect to hosts and automatically configure them with ease, but what if the hosts are dynamic and you don't know their IP addresses or hostnames in advance? Dynamic inventories come in to solve this problem by building your inventory on the fly based on an external data source. Notable dynamic inventories include the AWS EC2 dynamic inventory plugin, GCP dynamic inventory plugin, and Azure dynamic inventory plugin. A custom Spacelift dynamic inventory called Tofusible was built specifically for OpenTofu and Ansible using stack dependencies feature. The Tofusible dynamic inventory allows you to create hosts using OpenTofu and pass those hosts dynamically to Ansible for configuration. It uses the `tofusible_host` module to gather information about virtual machines created in OpenTofu, which is then passed to an Ansible stack using a stack dependency feature. The Ansible stack uses the `tofusible` dynamic inventory plugin to read this output and generate an inventory based on it, which is then used by Ansible to configure the virtual machines. To set up Tofusible, you need to create OpenTofu and Ansible stacks, create a virtual machine in OpenTofu, create a `tofusible_host` resource, output the host information, pass the output to the Ansible stack using a stack dependency feature, configure the dynamic inventory in your Ansible project, and finally run your playbook. The Tofusible dynamic inventory plugin is configured in a YAML file called `tofusible.yml`, which specifies the name of the input reference created in the stack dependency. The final step is to run your playbook, which will trigger the Ansible stack to use the Tofusible dynamic inventory plugin and configure the virtual machines.