New Question

Issue running powershell scripts in user_data (openstack configdriver)

asked 2016-07-17 07:40:45 +0300

eduardohki gravatar image

updated 2016-07-17 07:41:42 +0300


I'm trying to use user_data to run some powershell scripts in the host installation.

I followed the user_data documentation, and I tried the following script to add multiple IP's per NIC:


Set-Content C:\Windows\Temp\changeIP.ps1 "$IP = ("","","") $NetMask = "" $Gateway = "" $Dns = "" $IPType = "IPv4"

$adapter = Get-NetAdapter | ? {$_.Status -eq "up"}

If (($adapter | Get-NetIPConfiguration).IPv4Address.IPAddress) { $adapter | Remove-NetIPAddress -AddressFamily $IPType -Confirm:$false }

If (($adapter | Get-NetIPConfiguration).Ipv4DefaultGateway) { $adapter | Remove-NetRoute -AddressFamily $IPType -Confirm:$false }

ForEach ($address In $IP) { $ifName = $adapter.Name.ToString() If ($address -eq $IP[0]) { & netsh interface ipv4 add address "$ifName" $address $NetMask $Gateway } Else { & netsh interface ipv4 add address "$ifName" $address $NetMask } }

$adapter | Set-DnsClientServerAddress -ServerAddresses $DNS"

But the userdata execution doesn't work, and in the logs I receive the message "unsupported userdata format"

Any thoughts?

edit retag flag offensive close merge delete


I've already tried the script you pasted, as "user_data" file in the "latest" folder, but IDK is not working.

mariakatosvich gravatar imagemariakatosvich ( 2017-01-03 10:22:16 +0300 )edit

2 answers

Sort by » oldest newest most voted

answered 2016-07-21 00:34:22 +0300

puck gravatar image

Something to check - I just discovered this yesterday - what newlines are in your file? Unix style (just \n) won't work, you need \r\n. Try running "todos user_data" (or similar).

edit flag offensive delete link more


Actually I was editing them in Gedit, with the "CRLF" endline type. But I'll try it. Thanks!

eduardohki gravatar imageeduardohki ( 2016-07-22 21:44:32 +0300 )edit

answered 2016-07-18 12:47:52 +0300

avladu gravatar image

updated 2017-01-03 16:54:51 +0300


First of all, can you put the script in a pastebin, for better clarity?

Secondly, #ps1 is supported by cloudbase-init, but just to be sure, can you provide more details on your cloudbase-init version and OpenStack version?


You need to add the powershell script type to the begining of the local script content: #ps1 .
Example of a working script, based on the one you posted on pastebin:

Thank you.

edit flag offensive delete link more


This worked for me: cloudbase-init version 0.99

avladu gravatar imageavladu ( 2016-07-18 13:21:36 +0300 )edit

I'm using this in the Cloudbase Windows Image for KVM, using configDrive without OpenStack. I've already tried the script you pasted, as "user_data" file in the "latest" folder, but IDK why is not working... Thanks!

eduardohki gravatar imageeduardohki ( 2016-07-18 14:20:57 +0300 )edit

Hi, I've tested again and again, still no success. My user_data content is: The cloudbase-init.log is: The unattend log is: Thanks!

eduardohki gravatar imageeduardohki ( 2016-07-27 04:09:58 +0300 )edit

It might be some file encoding issue. Can you please set debug=true and report the output generated by cloudbase-init? Check also the encoding of the userdata file and ensure it's plain ANSI (you can use Notepad++ to check this easily). Also what EOL conversion are you using, Windows or UNIX?

alexpilotti gravatar imagealexpilotti ( 2017-01-03 10:33: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

[hide preview]

Question Tools

1 follower


Asked: 2016-07-17 07:40:45 +0300

Seen: 4,170 times

Last updated: Jan 03