manintheit.org

manintheit.org


Run VMware PowerCLI on your Docker Container

If you have a vSphere environment in your Infrastructure and want to automate provisioning steps, you are most likely need PowerCLI which mostly requires Windows Guest or supported GNU/Linux guest on your environment. By the way, Terraform also very nice tool to provision new virtual machine, but it is very limited.

If you stumble upon the same case above, this post for you. Actually you do not need any GNU/Linux or Window guest but docker. If you have a docker environment you can pull vmware/powerclicore image, run it in your docker environment and connect your vcenter server in that docker container.

I used it to set boot priority of virtual guests. One of the good thing with docker is that you can also pass your environment variables inside the container to use that variables.

docker run  --rm -it --entrypoint="/usr/bin/pwsh"  \
   -e VI_SERVER=${TF_VAR_vsphere_server} \
   -e VI_USERNAME=${TF_VAR_vsphere_user} \
   -v ${pwd}/scripts:/tmp/scripts vmware/powerclicore /tmp/scripts/setboot-priority.ps1

What above shell script does that, it instantiates docker image vmware/powerclicore mounts /scripts/ folder(where config.txt and setboot-priority.ps1 lives) on the host to /tmp/scripts in the container and run setboot-priority.ps1 in the container.

You can get setboot-priority.ps1 script from my github repo.



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.