Notes cloudinit

Voir :

https://readthedocs.org/projects/cloudinit/downloads/pdf/latest/

https://blog.octo.com/cloudinit-kesako/

https://www.scaleway.com/docs/how-to-use-cloud-init-to-configure-your-server-at-first-boot/

Voir aussi :

Tiny Cloud

ubuntu@vm-testjb1:~$ curl 169.254.169.254/1.0/meta-data/public-keys/0/openssh-key
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCZQwNs9aV//oN/N/NmbVqL83ahLatiVccLR1w2YEVBGX2fj5ANnj7a7hNk1tyld+CQlP93I6z7CW9bBxUjwwcxYWeVmBVRBLtFnjhN56gL7jGfXy6uwtUAf84tKWRem10tThIZhjWIIMHfDyFT7vVVN/hk9E3tQ7CejHK3NzhBUjDzrQ8yVIRynveNe93KNlCHW8T0rD83vqmEwApep/EuGD4rwb1e4zYAeh0HXVQIQzaoXlz8OwEBgzkvygCRrtUJcn3bQIloBmu2KrDvPskhqgCU4I9sbkN/K9PLn5hJVmhHVT3Prf0eU8hbrzdnfXlczmLbmVYTqUlOIvrvbAT jibe@vmdeb1ubuntu@vm-testjb1:~$

#cloud-config packages: - git-core #cloud-config apt_update: true #! echo "plop" > /plop environment: "production" output: {all: '| tee -a /var/log/cloud-init-output.log'}

**************************************************************************
# This system is using the EC2 Metadata Service, but does not appear to #
# be running on Amazon EC2 or one of cloud-init's known platforms that #
# provide a EC2 Metadata service. In the future, cloud-init may stop #
# reading metadata from the EC2 Metadata Service unless the platform can #
# be identified. #
# #
# If you are seeing this message, please file a bug against #
# cloud-init at #
# https://bugs.launchpad.net/cloud-init/+filebug?field.tags=dsid #
# Make sure to include the cloud provider your instance is #
# running on. #
# #
# For more information see #
# https://bugs.launchpad.net/bugs/1660385 #
# #
# After you have filed a bug, you can disable this warning by #
# launching your instance with the cloud-config below, or #
# putting that content into #
# /etc/cloud/cloud.cfg.d/99-ec2-datasource.cfg #
# #
# #cloud-config #
# datasource: #
# Ec2: #
# strict_id: false #
**************************************************************************
Disable the warnings above by:
touch /home/ubuntu/.cloud-warnings.skip
or
touch /var/lib/cloud/instance/warnings/.skip

DRAFT - Se connecter à une instance dont on ne possède pas la clef

Voir :

https://docs.aws.amazon.com/fr_fr/AWSEC2/latest/UserGuide/user-data.html

aws --region=eu-central-1 ec2 describe-instances --output=table

my_script.sh

#!/bin/bash cat >> /home/ec2-user/.ssh/authorized_keys <<EOF ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCZQwNs9aV//oN/N/NmbVqL83ahLatiVccLR1w2YEVBGX2fj5ANnj7a7hNk1tyld+CQlP93I6z7CW9bBxUjwwcxYWeVmBVRBLtFnjhN56gL7jGfXy6uwtUAf84tKWRem10tThIZhjWIIMHfDyFT7vVVN/hk9E3tQ7CejHK3NzhBUjDzrQ8yVIRynveNe93KNlCHW8T0rD83vqmEwApep/EuGD4rwb1e4zYAeh0HXVQIQzaoXlz8OwEBgzkvygCRrtUJcn3bQIloBmu2KrDvPskhqgCU4I9sbkN/K9PLn5hJVmhHVT3Prf0eU8hbrzdnfXlczmLbmVYTqUlOIvrvbAT jibe@vmdeb1 EOF sed -i 's/^PasswordAuthentication/#&/' /etc/ssh/sshd_config systemctl restart sshd
base64 my_script.sh > my_script_base64.txt
aws ec2 --region=eu-central-1 modify-instance-attribute --instance-id i-08df328706b9e6d46 --attribute userData --value file://my_script_base64.txt

Autres

/var/lib/cloud/data/set-hostname

File /etc/cloud/cloud-init.disabled

Kernel

cloud-init=disabled

Pb

Pb temps de démarrage élevé

# systemd-analyze
Startup finished in 3.195s (kernel) + 23.788s (userspace) = 26.983s
graphical.target reached after 23.230s in userspace
# systemd-analyze blame
11.755s cloud-init-local.service
5.854s docker.service
3.440s mariadb.service
2.459s cloud-init.service
2.317s isc-dhcp-server.service
1.984s php7.3-fpm.service
1.916s proftpd.service
1.200s cloud-config.service
1.138s ifupdown-pre.service
946ms bind9.service
911ms dev-mapper-vgos\x2droot

Logs

/var/log/cloud-init.log

/var/log/cloud-init-output.log

curl http://169.254.169.254/openstack/2018-08-27/meta_data.json

Solution

dpkg -i cloud-init_20.2-2~deb10u1_all.deb cloud-guest-utils_0.29-1_all.deb echo "network: {config: disabled}" > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg rm /etc/network/interfaces.d/50-cloud-init.cfg