How to use runcmd and scripts-user in cloud-init correctly?

After examining the runcmd code (/usr/lib/python2.6/site-packages/cloudinit/config/cc_runcmd.py) I noticed that there is no “frequency” specified compared to others. Besides all the scripts do, it saves the scripts defined as shell scripts in / var / lib / cloud / instance / scripts / runcmd.

Therefore, if I specify the modules in detail, I MUST set the frequency.

cloud_config_modules: - mounts - locale - set-passwords - timezone - [ runcmd, always ] cloud_final_modules: - scripts-per-once - scripts-per-boot - scripts-per-instance - [ scripts-user, always ] - ssh-authkey-fingerprints 

and scripts created by this particular one can be executed by "scripts-user", so I need to specify ie

 - [ scripts-user, always ] 

for runcmd scripts to work

Is this right to do? The documentation (at least 0.7.7 currently) lacks a proper explanation of runcmd and user scripts and their use

I also do not understand the difference between all modes, once (at the first start of the instance), instance (???), always (what I understand), ???? boot (the one that exists? Seems to work ...

EDIT:

ok, I found in cloudinit / settings.py:

 # Valid frequencies of handlers/modules PER_INSTANCE = "once-per-instance" PER_ALWAYS = "always" PER_ONCE = "once" 

and next to this, I found an explanation in this script:

 [ root@euca-10-254-97-216 ~]# cloud-init-per -h Usage: cloud-init-per frequency name cmd [ arg1 [ arg2 [ ... ] ] run cmd with arguments provided. This utility can make it easier to use boothooks or bootcmd on a per "once" or "always" basis. If frequency is: * once: run only once (do not re-run for new instance-id) * instance: run only the first boot for a given instance-id * always: run every boot 

But I do not understand the difference between "once" and "instance". So, if the same image (rather a snapshot) with a new instance identifier doesn’t start in the case of “once”? in the case of "instance" will it be?

+5
source share
1 answer

I think the difference matters if you create an image that will be used to run more instances.

Imagine you are running cloud-init scripts to install an instance. Later, you will create an image of this instance from which you can run more instances.

When you start a new instance with an image:

  • scripts with a frequency of "once" will not be run again
  • scenarios with a frequency “instance” will be launched at the first boot and will never be in this instance of life again
  • scripts with a frequency of "always" will be run during each download
+1
source

Source: https://habr.com/ru/post/1235757/


All Articles