Skip to content

Instantly share code, notes, and snippets.

@advanceboy
Last active April 25, 2024 15:13
Show Gist options
  • Save advanceboy/c9b020fe09ababd390c0e95d74dfde7e to your computer and use it in GitHub Desktop.
Save advanceboy/c9b020fe09ababd390c0e95d74dfde7e to your computer and use it in GitHub Desktop.
Ubuntu Server for Raspberry Pi の cloud-init 初期化スクリプトの書き換え例です
Ubuntu Server for Raspberry Pi の cloud-init 初期化スクリプトの書き換え例です
# This file contains a netplan-compatible configuration which cloud-init will
# apply on first-boot (note: it will *not* update the config after the first
# boot). Please refer to the cloud-init documentation and the netplan reference
# for full details:
#
# https://netplan.io/reference
# https://cloudinit.readthedocs.io/en/latest/topics/network-config.html
# https://cloudinit.readthedocs.io/en/latest/topics/network-config-format-v2.html
#
# Please note that the YAML format employed by this file is sensitive to
# differences in whitespace; if you are editing this file in an editor (like
# Notepad) which uses literal tabs, take care to only use spaces for
# indentation. See the following link for more details:
#
# https://en.wikipedia.org/wiki/YAML
#
# Additionally, please be aware that if your boot sequence depends on active
# networking (e.g. if your cloud-init configuration pulls packages or SSH
# keys from the network), you *must* mark at least one interface as required
# ("optional: false") below. Otherwise, particularly on faster boards,
# cloud-init will start attempting to use the network before it is ready
# Some additional examples are commented out below
network:
version: 2
ethernets:
eth0:
dhcp4: true
optional: true
wifis:
wlan0:
dhcp4: true
access-points:
"SSID-of-myhomewifi":
password: "password-of-myhomewifi"
#cloud-config
# This is the user-data configuration file for cloud-init. By default this sets
# up an initial user called "ubuntu" with password "ubuntu", which must be
# changed at first login. However, many additional actions can be initiated on
# first boot from this file. The cloud-init documentation has more details:
#
# https://cloudinit.readthedocs.io/
#
# Please note that the YAML format employed by this file is sensitive to
# differences in whitespace; if you are editing this file in an editor (like
# Notepad) which uses literal tabs, take care to only use spaces for
# indentation. See the following link for more details:
#
# https://en.wikipedia.org/wiki/YAML
#
# Some additional examples are provided in comments below the default
# configuration.
# Override the `default_user` configuration from `/etc/cloud/cloud.cfg`. The `user` dictionary keys supported for the default_user are the same as the `users` schema.
user:
name: newusername
# On first boot, set the (default) ubuntu user's password to "ubuntu" and
# expire user passwords
chpasswd:
expire: true
users:
- name: newusername
password: newpassword
type: text
## Set the system's hostname. Please note that, unless you have a local DNS
## setup where the hostname is derived from DHCP requests (as with dnsmasq),
## setting the hostname here will not make the machine reachable by this name.
## You may also wish to install avahi-daemon (see the "packages:" key below)
## to make your machine reachable by the .local domain
hostname: ubuntu-raspi5
## Set up the keyboard layout. See localectl(1), in particular the various
## list-x11-* sub-commands, to determine the available models, layouts,
## variants, and options
keyboard:
model: pc105
layout: jp
# variant:
# options: ctrl:nocaps
# Controls password authentication with the SSH daemon; the default here
# prevents logging into SSH with a password. Changing this is a security risk
# and you should at the very least ensure a different default password is
# specified above
ssh_pwauth: false
## On first boot, use ssh-import-id to give the specific users SSH access to
## the default user
#ssh_import_id:
#- lp:my_launchpad_username
#- gh:my_github_username
ssh_authorized_keys:
- ssh-rsa AAAA<中略>== rsa-key-of-user1
## Add users and groups to the system, and import keys with the ssh-import-id
## utility
#groups:
#- robot: [robot]
#- robotics: [robot]
#- pi
#
#users:
#- default
#- name: robot
# gecos: Mr. Robot
# primary_group: robot
# groups: users
# ssh_import_id: foobar
# lock_passwd: false
# passwd: $5$hkui88$nvZgIle31cNpryjRfO9uArF7DYiBcWEnjqq7L1AQNN3
## Update apt database and upgrade packages on first boot
#package_update: true
#package_upgrade: true
## Install additional packages on first boot
#packages:
#- avahi-daemon
#- rng-tools
#- python3-gpiozero
#- [python3-serial, 3.5-1]
# locale and timezone
timezone: Asia/Tokyo
## Write arbitrary files to the file-system (including binaries!)
write_files:
- path: /etc/cloud/cloud-init.disabled
defer: true
#- path: /etc/default/console-setup
# content: |
# # Consult the console-setup(5) manual page.
# ACTIVE_CONSOLES="/dev/tty[1-6]"
# CHARMAP="UTF-8"
# VIDEOMODE=
# FONT="Lat15-Terminus18x10.psf.gz"
# FONTFACE=
# FONTSIZE=
# CODESET="Lat15"
# permissions: '0644'
# owner: root:root
#- encoding: gzip
# path: /root/Makefile
# content: !!binary |
# H4sICF2DTWIAA01ha2VmaWxlAFNWCM8syVBILMjPyU/PTC1WKMlXiPB2dlFQNjSx5MpNteLi
# dLDiSoRQxYl5KeWZyRkgXrSCkoqKRmaKgm6pppKCbmqhgoFCrIKamkK1QmpyRr6Ckn92YqWS
# NdC80uQMBZhOa4VahZoaqIrwjMQSewXfxOxUhcwShcr80qLi1Jw0RSUuAIYfEJmVAAAA
# owner: root:root
# permissions: '0644'
## Run arbitrary commands at rc.local like time
runcmd:
# after wlan0 is connected, write the arp entry to target machine on background job
- [ sh, -c, 'sleep 2; ping -c 4 192.168.0.2' ]
#- [ ls, -l, / ]
#- [ sh, -xc, "echo $(date) ': hello world!'" ]
#- [ wget, "http://ubuntu.com", -O, /run/mydir/index.html ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment