New Question

userdata and powershell script on cloudbase-init

asked 2017-06-29 07:25:10 +0300

Nebukazar gravatar image


We're currently developing powershell scripts to automate our windows server guest deployment but we're facing some issues and therefore, having some questions:

1) Does cloudbase-init support script URL inclusion when specifying userdata ? eg:


2) Is there any code parsing issue ? Our code doesn't seem to be running and is causing some exception to be thrown. This is when we're giving the code directly within userdata (-vs- specifying an inclusion as mentioned above).

Please note the code is running just fine when we're executing it directly within the instance.

Please also note that userdata powershell script that only has a few lines with no special character is working fine as well eg:

net user blabla pwd123

So here is the cloudbase-init log snippet:

2017-06-28 23:45:51.058 2640 DEBUG cloudbaseinit.plugins.common.userdatautils [-] User_data stderr:
b'At C:\\Users\\cloudbase-init\\AppData\\Local\\Temp\\9d2a38d8-48fe-41fb-b8c1-b09007fadad1.ps1:72 char:31\r\n+ ... abet=$NULL;For ($a=65;$a \x83?"le 90;$a++) {$alphabet+=,[char][byte]$a }\r\n+                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\nUnexpected token \'\x83?"le 90;$a++) {$alphabet+=,[char][byte]$a }\r\n$ascii=$NULL;For ($a=33;$a \x83?"le\' in expression or statement.\r\nAt C:\\Users\\cloudbase-init\\AppData\\Local\\Temp\\9d2a38d8-48fe-41fb-b8c1-b09007fadad1.ps1:73 char:37\r\n+ $ascii=$NULL;For ($a=33;$a \x83?"le 126;$a++) {$ascii+=,[char][byte]$a }\r\n+                                     ~\r\nMissing closing \')\' after expression in \'for\' statement.\r\nAt C:\\Users\\cloudbase-init\\AppData\\Local\\Temp\\9d2a38d8-48fe-41fb-b8c1-b09007fadad1.ps1:73 char:42\r\n+ $ascii=$NULL;For ($a=33;$a \x83?"le 126;$a++) {$ascii+=,[char][byte]$a }\r\n+                                          ~\r\nUnexpected token \')\' in expression or statement.\r\nAt C:\\Users\\cloudbase-init\\AppData\\Local\\Temp\\9d2a38d8-48fe-41fb-b8c1-b09007fadad1.ps1:76 char:21\r\n+ For ($loop=1; $loop \x83?"le 9; $loop++) {\r\n+                     ~~~~~~~~~~~~~~~~~~~\r\nUnexpected token \'\x83?"le 9; $loop++) {\r\n\t$Username+=($alphabet | GET-RANDOM)\r\n}\r\necho "Username:\' in expression or statement.\r\nAt C:\\Users\\cloudbase-init\\AppData\\Local\\Temp\\9d2a38d8-48fe-41fb-b8c1-b09007fadad1.ps1:83 char:28\r\n+ For ($loop=1; $loop \x83?"le 9; $loop++) {\r\n+                            ~\r\nMissing closing \')\' after expression in \'for\' statement.\r\nAt C:\\Users\\cloudbase-init\\AppData\\Local\\Temp\\9d2a38d8-48fe-41fb-b8c1-b09007fadad1.ps1:83 char:37\r\n+ For ($loop=1; $loop \x83?"le 9; $loop++) {\r\n+                                     ~\r\nUnexpected token \')\' in expression or statement.\r\n    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException\r\n    + FullyQualifiedErrorId : UnexpectedToken\r\n \r\n' execute_user_data_script c:\program files\cloudbase solutions\cloudbase-init\python\lib\site-packages\cloudbaseinit\plugins\common\

3) Our windows guests are getting 2 interfaces. The first one is being configured as static ip address while the second one is using DHCP - it is basically matching our neutron subnet configurations. Due to some limitation, we cannot use DHCP on the primary interface / neutron subnet. Is there a way to speed up the static IP configuration process ? DHCP configuration happens within seconds while static network IP configuration takes minutes.

If that is not possible, is there a ... (more)

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2017-06-29 12:57:30 +0300

avladu gravatar image

updated 2017-06-29 13:04:48 +0300


For question 1: You might want to check the multipart userdata, where you can put multiple files on the disk using cloud-config writefiles (in gzip+base64 for example) or run multiple scripts. Here is a comprehensive example on what you can do: .

For question 2: Make sure your script does not have characters copied over from other sources like the dash - versus the long dash (em dash) .

For question 3: Can you give more details on what your looks like? We are currently working on a patch to support the neutron provided network config from the metadata. This way, cloudbase-init can set the static network configuration.

Thank you, Adrian Vladu

edit flag offensive delete link more


Thanks for your answers. #1 = I'll take a look and let you know if I encounter any issues. [...]

Nebukazar gravatar imageNebukazar ( 2017-06-29 21:49:22 +0300 )edit

#2 = The code appears to be working just fine locally; I don't think there is "special" character in the code as this wouldn't be able to execute locally. I'm doing some more testing by encoding the file and using some other alternatives. I'll keep you posted. [...]

Nebukazar gravatar imageNebukazar ( 2017-06-29 21:50:22 +0300 )edit

So basically, only #3 is pending at the moment. Thanks ! :)

Nebukazar gravatar imageNebukazar ( 2017-06-29 21:51:13 +0300 )edit

#3 = The guest is unable to reach that address (subnet is not using dhcp), I'm still seeing the following in the guest's cloud-init logfile: and content of the ConfigDrive's network_data.json : [...]

Nebukazar gravatar imageNebukazar ( 2017-06-29 21:52:12 +0300 )edit

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


Asked: 2017-06-29 07:25:10 +0300

Seen: 14,190 times

Last updated: Jun 29 '17