In vSphere 6.0 Update 1, the vCenter Server Appliance (VCSA) has received a significant enhancement to its Virtual Machine Management Interface also known as VAMI for short. As the name suggests, this interface provides basic configuration, monitoring and management capabilities for the Virtual Appliance which can be consumed through either a UI using a web browser or from the appliancesh CLI running within the VCSA Shell.
When talking to customers, they love the fact that the VCSA is harden out of the box and things like SSH are disabled by default. However, one challenge today is that if you need to access the appliancesh interface, SSH still must be enabled or direct console access would be required which is not ideal from an automation as well as from a security standpoint. Although things like SNMP can be configured on the VCSA to help alleviate some of these challenges, it does not solve the problem of having programmatic and remote management access.
VMware Engineering is aware of this request and is working on exposing the VAMI capabilities as an API in a future release of vSphere. In the mean time, not all hope is lost and there is still a solution which does not require you to give up security to be able to operate and manage your VCSA. We can do so by leveraging one of my all time favorite features of the vSphere Platform which is the Guest Operations API which allows you perform guest operations (running commands, transferring files, etc) directly within the guestOS as if you were logged in. Valid guest credentials are still required and once authenticated, the operations are then proxied through VMware Tools. Networking is not even required which makes this a really handy feature for troubleshooting and can even extend into application level provisioning using a single API. I can not stress enough on how cool and underutilized this feature is and it still comes as a surprise when I tell customers that this is actually possible.
Customers can consume the Guest Operations API by consuming it through one of our many supported vSphere SDKs as I have shown here or you can also consume it through PowerCLI using the Invoke-VMSCript cmdlet. To demonstrate the power of the Guest Operations API with the VCSA, I will completely disable all remote access to the VCSA which includes Local Login, Bash Shell and SSH as shown in the screenshot below.
Here is an example of running a simple "echo" command using the vSphere SDK for Perl:
Note: You will notice that there is no output and that is because the standard output must be re-directed to a file and then downloaded back to your client. The PowerCLI's Invoke-VMScript does handle this for you and will return any standand output to the console. For more complex commands, I would recommend creating a script that contains the command and just running the script itself which you can then log locally or into a file.
Here is an example of running the "appliancesh" command using the Invoke-VMScript cmdlet:
Invoke-VMScript -ScriptText "echo 'VMware1!' | appliancesh help pi list " -vm VCSA-No-SSH -GuestUser root -GuestPassword VMware1!
Here is an example of running the "cmsso-util" command using the Invoke-VMScript cmdlet:
Invoke-VMScript -ScriptText "export VMWARE_VAPI_HOME=/usr/lib/vmware-vapi export VMWARE_RUN_FIRSTBOOTS=/bin/run-firstboot-scripts export VMWARE_DATA_DIR=/storage export VMWARE_INSTALL_PARAMETER=/bin/install-parameter export VMWARE_LOG_DIR=/var/log export VMWARE_OPENSSL_BIN=/usr/bin/openssl export VMWARE_TOMCAT=/opt/vmware/vfabric-tc-server-standard/tomcat-7.0.55.A.RELEASE export VMWARE_RUNTIME_DATA_DIR=/var export VMWARE_PYTHON_PATH=/usr/lib/vmware/site-packages export VMWARE_TMP_DIR=/var/tmp/vmware export VMWARE_PERFCHARTS_COMPONENT=perfcharts export VMWARE_PYTHON_MODULES_HOME=/usr/lib/vmware/site-packages/cis export VMWARE_JAVA_WRAPPER=/bin/heapsize_wrapper.sh export VMWARE_COMMON_JARS=/usr/lib/vmware/common-jars export VMWARE_TCROOT=/opt/vmware/vfabric-tc-server-standard export VMWARE_PYTHON_BIN=/opt/vmware/bin/python export VMWARE_CLOUDVM_RAM_SIZE=/usr/sbin/cloudvm-ram-size export VMWARE_VAPI_CFG_DIR=/etc/vmware/vmware-vapi export VMWARE_CFG_DIR=/etc/vmware cmsso-util --help " -vm VCSA-No-SSH -GuestUser root -GuestPassword VMware1!
Note: The reason the additional "export" commands are required is that certain commands may rely on certain environmental variables to be setup. In the case of the cmsso-util command, there are several VMware environmental variables it uses. I decided to just export them all but you can selectively figure out which ones are truly needed.
As you can see from the examples above, I was able to successfully run both shell commands as well as the appliancesh without requiring SSH and even local login! This methods works whether you are connected to vCenter Server or ESXi host from vSphere API perspective.
UPDATE (06/06/19) - Example joining the VCSA to Active Directory using domainjoin-cli
Invoke-VMScript -ScriptText "echo 'VMware1!' | /opt/likewise/bin/domainjoin-cli join vmware.corp administrator
" -vm VCSA -GuestUser root -GuestPassword VMware1!