]> WPIA git - infra.git/blob - packer/debian-9/scripts/01-configure-cloudinit.sh
add: packer template for debian-9 installation
[infra.git] / packer / debian-9 / scripts / 01-configure-cloudinit.sh
1 #!/usr/bin/env bash
2
3 set -euo pipefail
4
5 # Configure cloud-init to allow image instanciation-time customization.
6 # The only cloud-init "datasources" that make sense for this image are:
7 #
8 # * "None": this is the last resort when nothing works. This prevents
9 #   cloud-init from exiting with an error because it didn't find any datasource
10 #   at all. This in turns allow to start the QEMU image with no
11 #
12 # * "NoCloud": this fetches the cloud-init data from a ISO disk mounted into
13 #   the new VM or from other non-network resources. See
14 #   https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html
15 #   for more information.
16 #
17 # Ultimately, this configures "datasource_list" in
18 # /etc/cloud/cloud.cfg.d/90_dpkg.cfg.
19 echo "cloud-init        cloud-init/datasources  multiselect     NoCloud, None" \
20         | debconf-set-selections
21
22 # Configure localepurge to remove unused locales. This makes the image smaller.
23 echo "localepurge       localepurge/use-dpkg-feature    boolean true" \
24         | debconf-set-selections
25 echo "localepurge       localepurge/nopurge     multiselect     en, en_US.UTF-8" \
26         | debconf-set-selections
27
28 # Reconfigure cloud-init
29 # Don't "lock" the "wpia" user password. It is configured directly by the
30 # preseeding and all the rest depends on it. Cloud-init, with the default
31 # configuration, overrides this user's settings and prevents from using it
32 # without a SSH key (which needs to be passed by the "cloud" user-data, which
33 # we may not always have.)
34 cat <<EOF > /etc/cloud/cloud.cfg.d/91-debian-user.cfg
35 # System and/or distro specific settings
36 # (not accessible to handlers/transforms)
37 system_info:
38    # This will affect which distro class gets used
39    distro: debian
40    # Default user name + that default users groups (if added/used)
41    default_user:
42      name: wpia
43      lock_passwd: false
44      gecos: Debian
45      groups: [adm, audio, cdrom, dialout, dip, floppy, netdev, plugdev, sudo, video]
46      sudo: ["ALL=(ALL) NOPASSWD:ALL"]
47      shell: /bin/bash
48    # Other config here will be given to the distro class and/or path classes
49    paths:
50       cloud_dir: /var/lib/cloud/
51       templates_dir: /etc/cloud/templates/
52       upstart_dir: /etc/init/
53    package_mirrors:
54      - arches: [default]
55        failsafe:
56          primary: http://deb.debian.org/debian
57          security: http://security.debian.org/
58    ssh_svcname: ssh
59 EOF
60
61 # Don't let cloud-init to take over the network configuration.
62 # This prevents to have more fine-grained configuration and enable lot of
63 # automagic configuration on interfaces that could (should!) be managed outside
64 # of cloud-init.
65 cat <<EOF > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
66 network:
67   config: disabled
68 EOF