Manage Cloud with Ansible
Manage your Cloud servers, firewalls, SSH keys and volumes with Ansible playbooks, and configure your servers through an inventory built from their tags.
Install the collection
The betterstack.betterstack collection needs ansible-core 2.15 or later.
Get an API token
Create a global API token in Settings → API tokens → Global tokens, and set it as the BETTERSTACK_API_TOKEN environment variable in the shell that runs Ansible.
Create your first server
Each data center is managed separately, so the playbook sets the one your resources are in as availability_zone, once for every task with module_defaults.
Save this playbook as cloud.yml. It adds your SSH key, a firewall that lets in SSH and HTTPS, a server that uses both, and a 10 GiB volume that the server mounts. Replace t123 with your team's ID from betterstack team list in the Cloud CLI:
The rules list is every rule the firewall has, so keep the outbound rule to let the server reach the internet. The modules find each resource by its name, or its slug for SSH keys, so running the playbook again changes only what differs.
To remove the resources, add state: absent to each task and run them in reverse order: the volume, the server, then the firewall.
Configure your servers
The betterstack.betterstack.servers inventory lists your servers in every data center as hosts and connects to each one's IPv4 address. Every tag in a server's metadata puts it in a group named tag_<key>_<value>, like tag_role_web.
Save the inventory as inventory.betterstack_cloud.yml. The plugin reads only a file whose name ends in betterstack_cloud.yml:
Install nginx on every server tagged role: web:
Need help?
Please let us know at hello@betterstack.com.
We're happy to help! 🙏