First, setup a Terraform provider as described in Simple WordPress setup with 1Password, Terraform, Ansible, and Docker on Linode. Then add the following to main.tf
:
resource "linode_instance" "foobaz" {
type = "g6-nanode-1"
image = "linode/ubuntu22.04"
region = "us-east"
tags = ["foobaz"]
authorized_keys = [var.ssh_key]
}
resource "linode_volume" "foobar" {
label = "foo-volume"
region = linode_instance.foobaz.region
linode_id = linode_instance.foobaz.id
size = 10
}
resource "ansible_host" "foobaz" {
name = tolist(resource.linode_instance.foobaz.ipv4)[0]
groups = ["foobaz"]
variables = {
volume_mnt = linode_volume.foobar.filesystem_path
}
}
Note that the image above must be specified or the volume cannot be created (it will return a 400 error).
Now create disk_demo.yml
playbook:
---
- name: Setup the filesystem
remote_user: root
hosts: foobaz
tasks:
- community.general.filesystem:
fstype: ext4
dev: "{{ hostvars[inventory_hostname].volume_mnt }}"
- ansible.posix.mount:
path: /mnt/storage
src: "{{ hostvars[inventory_hostname].volume_mnt }}"
fstype: ext4
state: mounted
Setup inventory.yml with
plugin: cloud.terraform.terraform_provider
binary_path: "./tfproxy.sh"
after creating tfproxy.sh
as described in Simple WordPress setup with 1Password, Terraform, Ansible, and Docker on Linode. Run ./tfproxy.sh plan
and then ./tfproxy.sh apply
if all is well.
Run the playbook: ansible-playbook -i inventory.yml disk_demo.yml
Start the discussion at forum.stereowrench.com