How to configure Cloudbase-init to run only local scripts (one by one) ?
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 ...
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
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