How-to
cloudbase-init¶
Run a PowerShell script on a Windows instance at its first boot, with user data. Breqwatr Cloud's Windows Server images include cloudbase-init, the Windows counterpart of cloud-init, which runs it.
How it works¶
- You pass a script as user data when you launch the instance.
- cloudbase-init runs it once, at the instance's first boot. Changing the user data later means launching a new instance.
- The script's first line tells cloudbase-init how to run it.
#ps1_sysnativeruns the rest as PowerShell. - cloudbase-init doesn't set the Administrator password. You set it on the console at first sign-in, as in Windows images.
Before you start¶
- A Windows Server image and what it needs to launch: see Windows images.
- A script. The example below adds a WinRM listener on HTTPS, with a self-signed certificate, and opens TCP 5986 in the Windows firewall, which is what Configuration with Ansible needs. Save it as
winrm-https.ps1:
#ps1_sysnative
$cert = New-SelfSignedCertificate -DnsName $env:COMPUTERNAME -CertStoreLocation Cert:\LocalMachine\My
New-Item -Path WSMan:\localhost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $cert.Thumbprint -Force
New-NetFirewallRule -DisplayName "WinRM over HTTPS" -Direction Inbound -Protocol TCP -LocalPort 5986 -Action Allow
Launch with user data¶
On New instance in the Breqwatr Cloud Portal (Strata), choose the Windows Server image, then paste the script into User data (optional).
Check it worked¶
The first boot takes several minutes. For the example script, port 5986 then answers, if the instance's security group allows it from your IP address:
Related¶
- Windows images: the images, and the first sign-in.
- Pets vs cattle: why configuration belongs in code and user data, not in hand-made changes.
- Configuration with Ansible: the tutorial this script comes from.
- cloudbase-init documentation: every plugin and user data format.