Comment 2 for bug 1781039

Revision history for this message
Shane Peters (shaner) wrote :

I've tested a "first boot" scenario using a customised image with this patched cloud-init and it works as expected (you can see both cloudinit and ubuntu keys above the 'Added by google' comment).

$ cat googlekeys
carbon:ssh-rsa AAAAB....ZCRI2M shaner@carbon
ubuntu:ssh-rsa AAAAB....65Otq/ shaner@ubuntu
cloudinit:ssh-rsa AAAA..6s3oSv shaner@cloudinit

# USING CUSTOM IMAGE WITH UPGRADED CLOUD-INIT
#############################################
$ gcloud compute instances create trusty1 --image custom-cloud-init --image-project firm-lacing-209716 --metadata-from-file=ssh-keys=googlekeys --metadata=block-project-ssh-keys=True
$ ssh ubuntu@x.x.x.x cat .ssh/authorized_keys
ssh-rsa AAAAB....65Otq/ shaner@ubuntu
ssh-rsa AAAA..6s3oSv shaner@cloudinit
# Added by Google
ssh-rsa AAAAB....65Otq/ shaner@ubuntu

# USING EXISTING IMAGE
################################
$ gcloud compute instances create trust2 --image-family ubuntu-1404-lts --image-project ubuntu-os-cloud --metadata-from-file=ssh-keys=googlekeys --metadata=block-project-ssh-keys=True

$ ssh ubuntu@${IP} cat .ssh/authorized_keys
# Added by Google
ssh-rsa AAAAB.....z65Otq/ shaner@ubuntu

$ scp cloud-init_0.7.5-0ubuntu1.23_all.deb ubuntu@${IP}:~/
$ ssh ubuntu@${IP} sudo dpkg -i cloud-init_0.7.5-0ubuntu1.23_all.deb
$ ssh ubuntu@${IP} sudo rm -rf /var/lib/cloud/instances
$ ssh ubuntu@${IP} sudo reboot
$ ssh ubuntu@${IP} cat .ssh/authorized_keys
ssh-rsa AAAA.....6s3oSv shaner@cloudinit
# Added by Google
ssh-rsa AAAAB....65Otq/ shaner@ubuntu

You'll notice in this second example, the 'ubuntu' key from my googlekeys file isn't added on top like you would expect if the image had an upgraded cloud-init. This is because the code is duplicate checking and won't add a key if it already exists.