Hi Everyone i am trying to create Mailcow server into my server through scripts while creating Hetzner server currently i create Hetzner server through API and pass to create mailcow server scripts through payload the same scripts when i try to create manually it works and UI also accessible but through the API it didn’t works can you guys helps me here is a scripts that i try to run through Hetzner Payload
Payload for Hetzner
payload = {
name: “#{domain_name}”,
server_type: “cx22”,
image: “ubuntu-24.04”,
location: “nbg1”,
ssh_keys: [ Figaro.env.SSH_KEYS_NAME ],
public_net: { enable_ipv4: true, enable_ipv6: false },
start_after_create: true,
user_data: user_data
}
Scripts that i passed on user_data
<<SCRIPT
#cloud-config
runcmd:
- apt-get update && apt upgrade -y
- apt install -y ca-certificates curl gnupg
- curl -fsSL | sudo gpg –dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- echo “deb [arch=$(dpkg –print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] $(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- apt update
- apt install -y docker-ce docker-ce-cli containerd.io
- sudo usermod -aG docker $USER
- sudo curl -L “docker/composereleases/download/$(curl -s | grep ‘tag_name’ | cut -d’”' -f4)/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- sudo chmod +x /usr/local/bin/docker-compose
- sleep 30
- systemctl enable docker
- systemctl start docker
- sleep 10
# open ports
- ufw allow 80/tcp
- ufw allow 443/tcp
- ufw allow 25/tcp
- ufw allow 587/tcp
- ufw reload
# Set up mail server
- umask
- cd /opt/
- git clone https://github.com/mailcow/mailcow-dockerized
- cd mailcow-dockerized
- echo "MAILCOW_HOSTNAME=mail.#{domain_name}" >> mailcow.conf
- ./generate_config.sh
- docker-compose pull
- docker-compose up -d
- sleep 120
SCRIPT