# Custom cloud-init for Drone Autoscaler

**URL:** https://drone.discourse.group/t/custom-cloud-init-for-drone-autoscaler/5350
**Category:** Drone Support
**Created:** [April 24, 2019, 7:36pm UTC](https://drone.discourse.group/t/custom-cloud-init-for-drone-autoscaler/5350 "2019-04-24T19:36:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)
#### Post date: [April 24, 2019, 7:36pm UTC](https://drone.discourse.group/t/custom-cloud-init-for-drone-autoscaler/5350/1 "2019-04-24T19:36:58Z")

</div>

# How to customize the cloud-init template

You can customize your instance configuration by providing a custom cloud-init file. Below is sample cloud-init file that you can use as a baseline and customize.

```auto
#cloud-config

apt_reboot_if_required: false
package_update: false
package_upgrade: false

apt:
  sources:
    docker.list:
      source: deb [arch=amd64] https://download.docker.com/linux/ubuntu $RELEASE stable
      keyid: 0EBFCD88

packages:
  - docker-ce

write_files:
  - path: /etc/systemd/system/docker.service.d/override.conf
    content: |
      [Service]
      ExecStart=
      ExecStart=/usr/bin/dockerd
  - path: /etc/default/docker
    content: |
      DOCKER_OPTS=""
  - path: /etc/docker/daemon.json
    content: |
      {
        "dns": ["8.8.8.8", "8.8.4.4"],
        "hosts": ["0.0.0.0:2376", "unix:///var/run/docker.sock"],
        "tls": true,
        "tlsverify": true,
        "tlscacert": "/etc/docker/ca.pem",
        "tlscert": "/etc/docker/server-cert.pem",
        "tlskey": "/etc/docker/server-key.pem"
      }
  - path: /etc/docker/ca.pem
    encoding: b64
    content: {{ .CACert | base64 }}
  - path: /etc/docker/server-cert.pem
    encoding: b64
    content: {{ .TLSCert | base64 }}
  - path: /etc/docker/server-key.pem
    encoding: b64
    content: {{ .TLSKey | base64 }}

runcmd:
  - [systemctl, daemon-reload]
  - [systemctl, restart, docker]

```

You will need to provide your custom cloud-init file to the autoscale server. You can mount the file as a volume:

```auto
--volume=/path/on/host/init.yml:/path/in/container/init.yml

```

You will also need to tell the autoscale server where to find the file inside the container:

```auto
DRONE_AMAZON_USERDATA_FILE=/path/inside/container/init.yml

```

---

<div class="post-metadata">

### Author: ![shqear](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/shqear/32/5887_2.png) [@shqear](https://drone.discourse.group/u/shqear)
#### Post date: [October 28, 2019, 9:00am UTC](https://drone.discourse.group/t/custom-cloud-init-for-drone-autoscaler/5350/2 "2019-10-28T09:00:43Z")

</div>

Hi, Thank you to posting this  
I tried to follow same guide with DigitalOceans but it doesn’t work!  
I also tried to use the same init file here [https://autoscale.drone.io/configure/cloud-init/](https://autoscale.drone.io/configure/cloud-init/)  
it always stucks in staging state without any logging info to debug!  
this is my setup :

```auto
services: 
 drone-autoscaler:
    image: drone/autoscaler
    ports:
      - 8080:8080
    volumes:
      - autoscaler-data:/data:delegated
      - ./scripts:/scripts:ro
      - ./runner-init.yml:/init.yml
    environment:
      - DRONE_AGENT_TOKEN=${DRONE_AGENT_TOKEN}
      - DRONE_AGENT_CONCURRENCY=5
      - DRONE_POOL_MIN=0
      - DRONE_POOL_MAX=5
      - DRONE_SERVER_PROTO=https
      - DRONE_SERVER_HOST=${CICD_FQDN}
      - DRONE_SERVER_TOKEN=${DRONE_SERVER_TOKEN}
      - DRONE_DIGITALOCEAN_SSHKEY=${DRONE_DIGITALOCEAN_SSHKEY}
      - DRONE_DIGITALOCEAN_TOKEN=${DRONE_DIGITALOCEAN_TOKEN}
      - DRONE_DIGITALOCEAN_SIZE=s-4vcpu-8gb
      - DRONE_DIGITALOCEAN_TAGS=devops,drone,agent
      - DRONE_DIGITALOCEAN_REGION=lon1
      - DRONE_LOGS_COLOR=true
      - DRONE_SLACK_WEBHOOK=${ZEN_AUTOMATOR_SLACK_WEBHOOK}
      - DRONE_DIGITALOCEAN_USERDATA=#cloud-init
      - DRONE_DIGITALOCEAN_USERDATA_FILE=/init.yml

```

I also tried a very simple cloud-init file also doesn’t work :

```auto
#cloud-config
users:
  - name: demo
    groups: sudo
    shell: /bin/bash
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
runcmd:
  - [systemctl, daemon-reload]
  - [systemctl, restart, docker]

```

---

<div class="post-metadata">

### Author: ![shqear](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/shqear/32/5887_2.png) [@shqear](https://drone.discourse.group/u/shqear)
#### Post date: [October 28, 2019, 9:55am UTC](https://drone.discourse.group/t/custom-cloud-init-for-drone-autoscaler/5350/3 "2019-10-28T09:55:24Z")

</div>

Autoscaller service logs :

```auto
{"level":"debug","region":"lon1","image":"docker-18-04","size":"s-4vcpu-8gb","name":"agent-2XRwjhYP","name":"agent-2XRwjhYP","ip":"178.62.13.194","time":"2019-10-28T09:38:37Z","message":"instance network ready"}
{"level":"debug","server":"agent-2XRwjhYP","time":"2019-10-28T09:38:37Z","message":"provisioned server"}
{"level":"debug","ip":"178.62.13.194","name":"agent-2XRwjhYP","name":"agent-2XRwjhYP","time":"2019-10-28T09:38:45Z","message":"check docker connectivity"}
{"level":"debug","ip":"178.62.13.194","name":"agent-2XRwjhYP","name":"agent-2XRwjhYP","time":"2019-10-28T09:38:45Z","message":"connecting to docker"}
{"level":"debug","ip":"178.62.13.194","name":"agent-2XRwjhYP","error":"Cannot connect to the Docker daemon at https://178.62.13.194:2376. Is the docker daemon running?","name":"agent-2XRwjhYP","time":"2019-10-28T09:38:45Z","message":"cannot connect, retry in 1m0s"}
{"level":"debug","ip":"178.62.13.194","name":"agent-2XRwjhYP","name":"agent-2XRwjhYP","time":"2019-10-28T09:56:45Z","message":"connecting to docker"}
{"level":"debug","ip":"178.62.13.194","name":"agent-2XRwjhYP","error":"Cannot connect to the Docker daemon at https://178.62.13.194:2376. Is the docker daemon running?","name":"agent-2XRwjhYP","time":"2019-10-28T09:56:45Z","message":"cannot connect, retry in 1m0s"}
{"level":"debug","id":"ZJblZNy3da89SFpl","min-pool":0,"max-pool":5,"server-buffer":0,"server-capacity":5,"server-count":1,"pending-builds":0,"running-builds":0,"time":"2019-10-28T09:57:35Z","message":"check capacity"}
{"level":"debug","id":"ZJblZNy3da89SFpl","time":"2019-10-28T09:57:35Z","message":"terminate 1 servers"}
{"level":"debug","id":"ZJblZNy3da89SFpl","time":"2019-10-28T09:57:35Z","message":"no idle servers to shutdown"}
{"level":"debug","id":"ZJblZNy3da89SFpl","time":"2019-10-28T09:57:35Z","message":"check capacity complete"}
{"level":"debug","ip":"178.62.13.194","name":"agent-2XRwjhYP","name":"agent-2XRwjhYP","time":"2019-10-28T09:57:45Z","message":"connecting to docker"}
{"level":"debug","ip":"178.62.13.194","name":"agent-2XRwjhYP","error":"Cannot connect to the Docker daemon at https://178.62.13.194:2376. Is the docker daemon running?","name":"agent-2XRwjhYP","time":"2019-10-28T09:57:45Z","message":"cannot connect, retry in 1m0s"}

```
