Skip to content

Latest commit

 

History

History
99 lines (78 loc) · 2.22 KB

File metadata and controls

99 lines (78 loc) · 2.22 KB

Cloud-Init Integration

Minimal Cloud-Init User Data

#cloud-config
runcmd:
  - curl -fsSL https://raw.githubusercontent.com/bauer-group/IAC-Ansible/main/scripts/install.sh | bash

Without Cloud-Init (manual one-liner)

Not every provider supports cloud-init. For those, SSH into the freshly installed box as root and run the installer with IAC_HOSTNAME set to the matching inventory key:

curl -fsSL https://raw.githubusercontent.com/bauer-group/IAC-Ansible/main/scripts/install.sh | \
  IAC_HOSTNAME=0047-20.cloud.bauer-group.com bash

The installer runs hostnamectl, updates /etc/hosts and writes preserve_hostname: true to /etc/cloud/cloud.cfg before the first ansible-pull, so the host finds its own host_vars/<name>.yml from inventory. Idempotent — safe to re-run.

Full Cloud-Init User Data

#cloud-config

# Set timezone
timezone: Etc/UTC

# Ensure prerequisites
packages:
  - curl
  - git

# Bootstrap IAC-Ansible
runcmd:
  - |
    curl -fsSL https://raw.githubusercontent.com/bauer-group/IAC-Ansible/main/scripts/install.sh | \
      BRANCH=main \
      SCHEDULE="*-*-* 02:00:00" \
      bash

# Optional: Write custom host vars before first pull
write_files:
  - path: /etc/iac-ansible-labels
    content: |
      cloud
      production
    permissions: '0644'

Terraform Integration

resource "hcloud_server" "web" {
  name        = "0046-20"
  server_type = "cx21"
  image       = "ubuntu-24.04"

  user_data = <<-EOF
    #cloud-config
    runcmd:
      - curl -fsSL https://raw.githubusercontent.com/bauer-group/IAC-Ansible/main/scripts/install.sh | bash
  EOF
}

Hetzner Cloud

hcloud server create \
  --name 0046-20 \
  --type cx21 \
  --image ubuntu-24.04 \
  --user-data-from-file cloud-init.yml

AWS EC2

aws ec2 run-instances \
  --image-id ami-xxxxx \
  --instance-type t3.micro \
  --user-data file://cloud-init.yml

After Provisioning

  1. The installer runs automatically on first boot
  2. Ansible is installed
  3. ansible-pull is configured with systemd timer
  4. Initial pull runs and applies the configuration
  5. Add the new host to inventory/production/hosts.yml
  6. Commit and push - server will pick up group assignments on next pull