Skip to content

Instantly share code, notes, and snippets.

@berkant
Last active April 26, 2024 17:58
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save berkant/6768ad670b198b0f36b62edbf97c55a3 to your computer and use it in GitHub Desktop.
Save berkant/6768ad670b198b0f36b62edbf97c55a3 to your computer and use it in GitHub Desktop.
Cloud-init config to set up my Ubuntu dev machine.
## template: jinja
#cloud-config
{% if v1.distro_release == 'focal' %}
users:
- name: berkant
shell: /usr/bin/bash
ssh_import_id: gh:berkant
sudo: ALL=(ALL:ALL) NOPASSWD:ALL
chpasswd:
expire: false
apt_upgrade: true
apt:
sources:
caddy:
source: deb [trusted=yes] https://dl.cloudsmith.io/public/caddy/stable/deb/ubuntu focal main
neovim:
source: ppa:neovim-ppa/stable
hashicorp:
source: deb [trusted=yes] https://apt.releases.hashicorp.com focal main
speedtest:
source: deb [trusted=yes] https://packagecloud.io/ookla/speedtest-cli/ubuntu focal main
tailscale:
source: deb [trusted=yes] https://pkgs.tailscale.com/stable/ubuntu focal main
packages:
- python-is-python3
- build-essential
- python3-pip
- p7zip-full
- traceroute
- mediainfo
- speedtest
- tailscale
- neofetch
- mlocate
- ffmpeg
- iperf3
- neovim
- screen
- vnstat
- aria2
- caddy
- iftop
- unzip
- whois
- curl
- file
- htop
- tree
- wget
- cbm
- git
- mtr
- jq
runcmd:
- tailscale up -authkey='<% EDIT_THIS_FIELD_YourNodeAuthKey %>'
- ufw --force reset
- ufw allow in on tailscale0 to any
- ufw --force enable
- sed -i '1i PermitRootLogin no' /etc/ssh/sshd_config
- sed -i '1i PasswordAuthentication no' /etc/ssh/sshd_config
- sed -i '1i ClientAliveInterval 5' /etc/ssh/sshd_config
- systemctl --no-block restart sshd
- pip3 install youtube-dl httpie nyx
- wget -O /tmp/rclone.deb https://github.com/rclone/rclone/releases/download/v1.55.1/rclone-v1.55.1-linux-amd64.deb
- dpkg -i /tmp/rclone.deb
- wget -O /tmp/bat.deb https://github.com/sharkdp/bat/releases/download/v0.18.0/bat_0.18.0_amd64.deb
- dpkg -i /tmp/bat.deb
- mkdir -p /opt/nvm
- wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | NVM_DIR=/opt/nvm bash
- printf '\nexport NVM_DIR="/opt/nvm"\n[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"\n' >> /etc/bash.bashrc
- wget -O /tmp/bento4.zip http://zebulon.bok.net/Bento4/binaries/Bento4-SDK-1-6-0-637.x86_64-unknown-linux.zip
- unzip /tmp/bento4.zip -d /opt
- printf '\nexport PATH="$PATH:/opt/Bento4-SDK-1-6-0-637.x86_64-unknown-linux/bin"\n' >> /etc/bash.bashrc
{% endif %}
@AysadKozanoglu
Copy link

AysadKozanoglu commented Oct 30, 2022

for your interest about runcmd parameter:

  • runcmd only has code to "shellify" your strings or array of strings (i.e: turns them into a shell script)
  • runcmd will only write a shell script into the file /var/lib/cloud/instance/scripts/runcmd
  • runcmd is part of the cloud_config_modules boot stage
  • You need to execute that runcmd shell script using the scripts-user module
  • scripts-user is part of the cloud_final_modules boot stage

example for runcmd command with executing while running cloud-init

cloud_config_modules:
  - runcmd

cloud_final_modules:
  - scripts-user

runcmd:
  - [ touch, /tmp/myfile ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment