New Question
0

How to configure Cloudbase-init to run only local scripts (one by one) ?

asked 2021-01-18 19:18:36 +0300

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi,

I'm new to using Cloudbase-Init (version: 1.1.2) with Windows Server 2019 (which is an openstack image). And what i should orchestrate with cloudbase-init is only to run some local scripts that are included locally in the image, and I should configure cloudbase-init to run all my local scripts one by one.

But i still did not find the right configuration!

According to the documentation, i saw that in my uses case i should use EmptyMetadataService while i'm going to use only LocalScriptsPlugin.

this is what i have as the cloudbase-init.conf config file:


[DEFAULT]

username=Admin

groups=Administrators

injectuserpassword=true

configdriveraw_hhd=true

configdrivecdrom=true

configdrivevfat=true

bsdtar_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\bin\bsdtar.exe

mtools_path=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\bin\

verbose=true

debug=true

logdir=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\log\

logfile=cloudbase-init.log

defaultloglevels=comtypes=INFO,suds=INFO,iso8601=WARN,requests=WARN

loggingserialport_settings=

mtuusedhcp_config=true

ntpusedhcp_config=true

localscriptspath=C:\Program Files\Cloudbase Solutions\Cloudbase-Init\LocalScripts\

checklatestversion=true

metadata_services=

plugins=cloudbaseinit.plugins.common.localscripts.LocalScriptsPlugin

...

And like a test, i used my test.ps1 script in C: \ Program Files \ Cloudbase Solutions \ Cloudbase-Init \ LocalScripts \:

my test.ps1 script :

#ps1_sysnative

Start-Transcript -path C:\cloudbase-init-firstboot.log -Append -force

write-output "test cloudbase-init local script"

stop-transcript

exit 1001

...

and after restarting the cloudbase-init service it looks like my test.ps1 script was not executed.

Here is what i get in my cloudbase-init log file after reboot:

2021-01-18 17:10:45.021 3444 DEBUG cloudbaseinit.utils.classloader [-] Loading class 'cloudbaseinit.osutils.windows.WindowsUtils' load_class C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\utils\classloader.py:27

2021-01-18 17:10:45.568 3444 DEBUG cloudbaseinit.osutils.windows [-] Checking if service exists: cloudbase-init checkserviceexists C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\osutils\windows.py:1092

2021-01-18 17:10:45.568 3444 DEBUG cloudbaseinit.osutils.windows [-] Getting service username: cloudbase-init getserviceusername C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\osutils\windows.py:1225

2021-01-18 17:10:45.568 3444 DEBUG cloudbaseinit.osutils.windows [-] Resetting password for service user: .\cloudbase-init resetservicepassword C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\osutils\windows.py:1248

2021-01-18 17:10:45.646 3444 DEBUG cloudbaseinit.osutils.windows [-] Setting service credentials: cloudbase-init setservicecredentials C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\osutils\windows.py:1208

2021-01-18 17:10:45.662 3444 INFO cloudbaseinit.init [-] Respawning current process with updated credentials.

2021-01-18 17:10:45.662 3444 DEBUG cloudbaseinit.osutils.windows [-] Creating logon session for user: .\cloudbase-init createuserlogon_session C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\osutils\windows.py:649

2021-01-18 17:10:45.678 3444 DEBUG cloudbaseinit.osutils.windows [-] Executing process as user, command line: ['C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\Scripts\cloudbase-init', '--config-file', 'C:\Program Files\Cloudbase Solutions\Cloudbase-Init\conf ... (more)

edit retag flag offensive close merge delete

Comments

i was able to execute my local script by adding metadata_services=cloudbaseinit.metadata.services.base.EmptyMetadataService to my conf file. but my script still executed on each time i rebooted my server even i'd set up 1001 like exit code in my script

western12 gravatar imagewestern12 ( 2021-01-19 12:53:35 +0300 )edit

2021-01-19 11:47:36.662 4284 INFO cloudbaseinit.plugins.common.fileexecutils [-] Script "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\LocalScripts\test.ps1" ended with exit code: 1001 2021-01-19 11:47:36.662 4284 INFO cloudbaseinit.init [-] Plugins execution done 2021-01-19 11:47:36.662 4284

western12 gravatar imagewestern12 ( 2021-01-19 12:53:52 +0300 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2021-01-19 15:51:30 +0300

avladu gravatar image

Hello,

Please check the EmptyMetadataService notes: https://cloudbase-init.readthedocs.io...:

If a service returns an empty instance-id (like EmptyMetadataService does), all the plugins will be executed at every cloudbase-init run (reboot, service restart). Plugins that set NTP, MTU, extend volumes are idempotent and can be re-executed with no issues. Make sure that if you configure cloudbase-init to run local scripts, those local scripts are idempotent.

Make sure your scripts are idempotent, meaning that every time the scripts are executed, the result is the same.

Example:

if is_unwanted_state():
  set_wanted_state()

You can still use the exit reboot codes, but with the above considerations.

Thank you,
Adrian Vladu

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-01-18 19:18:36 +0300

Seen: 6,891 times

Last updated: Jan 19 '21