forcerk
Enthusiast
Enthusiast

vRA8 On Prem Windows deployment with CloudBase Init

Jump to solution

Hello all,

does anyone have a running Windows Blueprint which is using CloudBase-Init to customize the deployed VM?

So far I've managed to replicate the deployment like shown at this vmware blog post.

So the hostname customization is working. But I'm not able to implement the following things:

1. Change the first_logon_behaviour that no password change is needed for the next logon.

     So far I've changed added the line "first_logon_behaviour=no" to the cloudbase-init-unattend.conf. But I still have to change the password at the first logon.

2. I don't understand how to use the user data plugin to run powershell scripts.

Tags (1)
1 Solution

Accepted Solutions
forcerk
Enthusiast
Enthusiast

I've found out how to execute scripts. Here is my Blueprint YAML how I've managed to create the scripts with input from the blueprints and execute them.

formatVersion: 1

inputs:

  name:

    type: string

    description: Hostname for the VM.

  IP:

    type: string

    title: IP for the VM

    description: IP for the new deployed VM

...

cloudConfig: |

        #cloud-config

        write_files:

          content: |

            New-NetIPAddress -InterfaceIndex 1 -IPAddress ${input.IP} -PrefixLength 24

            Set-DnsClientServerAddress -InterfaceIndex 1 -ServerAddresses ("10.10.10.10","8.8.8.8")

            Set-DnsClient -Interface 1 -ConnectionSpecificSuffix "domain.com"

          path: C:\Scripts\NetworkConfig.ps1

        set_hostname: '${input.name}'

        set_timezone: Europe/Berlin

        ntp:

          enabled: True

          servers: ['ntp.domain.com']

        runcmd:

          - 'PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList (Set-ExecutionPolicy Unrestricted -Force) -Verb RunAs}"'

          - 'PowerShell C:\\Scripts\\NetworkConfig.ps1'

The first line from the runcmd is setting the Powershell ExecutionPolicy to Unrestriced that I can execute my created ps1 scripts.

Maybe this is helping someone in the future Smiley Happy

View solution in original post

5 Replies
forcerk
Enthusiast
Enthusiast

I've figured out why the first_logon_behaviour wasn't working.

My mistake was to set the option at the "cloudbase-init-unattend.conf" instead of the "cloudbase-init.conf.

So I've fixed this issue I had. Now I'm working on how to start powershell scripts that will do all the stuff that is not included so far.

Like domain join, IP settings etc.

0 Kudos
pizzle85
Expert
Expert

I don't think the ovf method described on the link you posted supports the scripting plugin. If you look at the list of plugins in your file it does not include the scripting one

classcloudbaseinit.plugins.common.localscripts.LocalScriptsPluginhttps://cloudbase-init.readthedocs.io/en/latest/plugins.html#cloudbaseinit.plugins.common.localscrip...

For our Linux deployments we're pushing the config and userData YAML as VM guest info then using the coloudinit VMware Guest Info service to pull the YAML from the VM guest info and using that to build. Its not cloud agnostic but it fulfills all the requirements of our deployments on prem so we may opt to go that route again with windows.

0 Kudos
forcerk
Enthusiast
Enthusiast

Thanks pizzle85 for your reply. So far I havn't used the VMware Guest Info Service.

My approach so far is to use the class cloudbaseinit.metadata.services.ovfservice.OvfService and then use the user data to execute Powershell scripts.

But I'm not finding a way how to do this. So if anyone does have an example that would be great.

0 Kudos
forcerk
Enthusiast
Enthusiast

Hello all,

I've did some more testing and found a way how I might be able to do it. Here is what I've did so far.

As mentioned I'm using the Open Virtualization Format Service. So far I've didn't found a way how to use the PowerShell user data. Maybe that is not supported by the OVF Service for now.

But what I'm able to utilize is the "Cloud config" user data. So out of the box I can configure the timzone, hostname, ntp and create some files.

So my idea is to use write_files together with the bluepirint inputs to create my powershell scripts for setting IP, join the domain and other customizations.

This is working like this:

inputs:

     IP:

          type: string

          title: IP for the VM

...

cloudConfig:

     #cloud-config

          write_files:

               content: Set-Content -Path C:\MyIP.txt -Value "My IP is  ${input.IP}"

This will create a text file with the IP from the blueprint input.

Right now I just like to use the command "runcmd" to execute the scripts that I've creating with #cloud-config.

I've tried it with the following code which didn't work.

#cloud-config

     runcmd:

          - 'powershell.exe C:\path\to\script.ps1'

But this didn't work so far. Also the logs doesn't really help me. I see the runcmd command been excuted and the return value of 0.

If somebody can tell me how to execute scripts via runcmd would help a lot.

cheers

0 Kudos
forcerk
Enthusiast
Enthusiast

I've found out how to execute scripts. Here is my Blueprint YAML how I've managed to create the scripts with input from the blueprints and execute them.

formatVersion: 1

inputs:

  name:

    type: string

    description: Hostname for the VM.

  IP:

    type: string

    title: IP for the VM

    description: IP for the new deployed VM

...

cloudConfig: |

        #cloud-config

        write_files:

          content: |

            New-NetIPAddress -InterfaceIndex 1 -IPAddress ${input.IP} -PrefixLength 24

            Set-DnsClientServerAddress -InterfaceIndex 1 -ServerAddresses ("10.10.10.10","8.8.8.8")

            Set-DnsClient -Interface 1 -ConnectionSpecificSuffix "domain.com"

          path: C:\Scripts\NetworkConfig.ps1

        set_hostname: '${input.name}'

        set_timezone: Europe/Berlin

        ntp:

          enabled: True

          servers: ['ntp.domain.com']

        runcmd:

          - 'PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList (Set-ExecutionPolicy Unrestricted -Force) -Verb RunAs}"'

          - 'PowerShell C:\\Scripts\\NetworkConfig.ps1'

The first line from the runcmd is setting the Powershell ExecutionPolicy to Unrestriced that I can execute my created ps1 scripts.

Maybe this is helping someone in the future Smiley Happy

View solution in original post