|
| 1 | +#cloud-config |
| 2 | +users: |
| 3 | +%{ for user in users} |
| 4 | + - name: ${user.user_name} |
| 5 | + groups: sudo |
| 6 | + shell: /bin/bash |
| 7 | + sudo: 'ALL=(ALL) NOPASSWD:ALL' |
| 8 | + ssh-authorized-keys: |
| 9 | + - ${user.ssh_public_key} |
| 10 | +%{ endfor} |
| 11 | + |
| 12 | + |
| 13 | +runcmd: |
| 14 | +- apt-get update |
| 15 | +- apt-get upgrade |
| 16 | + |
| 17 | + |
| 18 | +# mount disk if provided |
| 19 | +%{ if extra_disk_id != "" } |
| 20 | +# Prepare partition on secondary disk |
| 21 | +- mkdir -p ${extra_path} |
| 22 | +- echo "mkdir" >> /home/tux/log.txt |
| 23 | +- parted -s /dev/disk/by-id/virtio-${extra_disk_id} mklabel gpt >> /home/tux/log.txt |
| 24 | +- parted -s /dev/disk/by-id/virtio-${extra_disk_id} mkpart primary ext4 0% 100% >> /home/tux/log.txt |
| 25 | +- sync |
| 26 | +- echo "sync" >> /home/tux/log.txt |
| 27 | +- mkfs.ext4 /dev/disk/by-id/virtio-${extra_disk_id}-part1 >> /home/tux/log.txt |
| 28 | +- sync |
| 29 | +- mount -o rw /dev/disk/by-id/virtio-${extra_disk_id}-part1 ${extra_path} >> /home/tux/log.txt |
| 30 | +- echo "/dev/disk/by-id/virtio-${extra_disk_id}-part1 ${extra_path} ext4 defaults 0 2" >> /etc/fstab |
| 31 | +- chown nobody:nogroup ${extra_path} |
| 32 | +- chmod 777 ${extra_path} |
| 33 | +%{ endif } |
| 34 | + |
| 35 | +# mount shared filesystem if provided |
| 36 | +%{if shared_filesystem_id != "" } |
| 37 | +- mkdir -p ${shared_filesystem_mount} |
| 38 | +- mount -t virtiofs filesystem-0 ${shared_filesystem_mount} |
| 39 | +- chmod a+w ${shared_filesystem_mount} |
| 40 | +- echo "filesystem-0 ${shared_filesystem_mount} virtiofs rw 0 0" >> /etc/fstab |
| 41 | +%{endif} |
| 42 | + |
| 43 | +# install s3 access |
| 44 | +%{if aws_access_key_id != ""} |
| 45 | +- snap install aws-cli --classic |
| 46 | + |
| 47 | +%{ for user in users} |
| 48 | +- mkdir -p /home/${user.user_name}/.aws |
| 49 | +- echo "[default]" > /home/${user.user_name}/.aws/credentials |
| 50 | +- echo "aws_access_key_id=${aws_access_key_id}" >> /home/${user.user_name}/.aws/credentials |
| 51 | +- echo "aws_secret_access_key=${aws_secret_access_key}" >> /home/${user.user_name}/.aws/credentials |
| 52 | +- echo "[default]" > /home/${user.user_name}/.aws/config |
| 53 | +- echo "endpoint_url = https://storage.eu-north1.nebius.cloud:443" >> /home/${user.user_name}/.aws/config |
| 54 | +- echo "region = eu-north1" >> /home/${user.user_name}/.aws/config |
| 55 | +- chown -R ${user.user_name}:${user.user_name} /home/${user.user_name}/.aws |
| 56 | +- chmod 600 /home/${user.user_name}/.aws/credentials |
| 57 | +%{ endfor } |
| 58 | + |
| 59 | +- mkdir -p /root/.aws |
| 60 | +- echo "[default]" > /root/.aws/credentials |
| 61 | +- echo "aws_access_key_id=${aws_access_key_id}" >> /root/.aws/credentials |
| 62 | +- echo "aws_secret_access_key=${aws_secret_access_key}" >> /root/.aws/credentials |
| 63 | +- echo "[default]" > /root/.aws/config |
| 64 | +- echo "endpoint_url = https://storage.eu-north1.nebius.cloud:443" >> /root/.aws/config |
| 65 | +- echo "region = eu-north1" >> /root/.aws/config |
| 66 | + |
| 67 | + |
| 68 | +# install s3 mount |
| 69 | + |
| 70 | +%{if mount_bucket != "" } |
| 71 | +- wget https://s3.amazonaws.com/mountpoint-s3-release/1.14.0/x86_64/mount-s3-1.14.0-x86_64.deb |
| 72 | +- dpkg -i mount-s3-1.14.0-x86_64.deb |
| 73 | +- mkdir -p ${s3_mount_path} |
| 74 | +- mount-s3 --upload-checksums=off --maximum-throughput-gbps=200 --allow-delete --allow-overwrite --allow-other --endpoint-url=https://storage.eu-north1.nebius.cloud:443 ${mount_bucket} ${s3_mount_path} |
| 75 | +%{endif} |
| 76 | +%{endif} |
0 commit comments