2

I want to automate customizing a user home directory when running GCE instance - like ~/.profile, ~/.vimrc, add some files into ~/.vim directory...

Seems to be very basic, but somehow I cannot figure out how to do this.

  1. --startup-script parameter of the gcloud command runs as a root, so I cannot refer to $HOME in it.
  2. the user is already created by the time startup script runs, so no point in adding files to /etc/skel directory.
rincewind
  • 1,103
  • 8
  • 29
  • If you're just looking for a quick way to be able to spawn new GCE instances with specific customizations, one option would be to do all of your customization once manually, and then spawn an image from the boot disk and spawn future GCE instances from that: https://cloud.google.com/compute/docs/images/create-delete-deprecate-private-images If your customization need is more dynamic, I would recommend using a configuration management tool such as Ansible, Chef, or Puppet to apply configuration post GCE instance spawning, which will give the added benefit of versioning the configuration. – Brandon DeRosier Jun 26 '18 at 04:47
  • Well, I'm ok with manually modifying the image (although not ideal - ideally, I'd like to keep all configuration "as a code"). But how can I customize it - even manually - to be username-independent? I am already using images - but I use it to install packages, mostly. Now I am talking about more dynamic configuration - I think it is possible via cloud-init, so was hoping that it is possible via gcloud command as well. – rincewind Jun 26 '18 at 05:42
  • @rincewind At the time of instance creation, In --startup-script, you can mention directory of single user E.g. `/home/vikas`. and If this is for all users, then first find all directories under `/home` and then run a loop over all directories and customize one by one. Also take care edge condition like handling of deleted users which have their directory in `/home`. – Vikas Saini Jun 26 '18 at 12:49
  • If you were able to solve this issue with the recommendations given above, can you post an answer for this thread that can be shared with the community? – Marilu Jul 05 '18 at 17:47

0 Answers0