Collecting guest level information from multiple VMs may be automated by shell scripting for Linux and Powershell scripting for Windows the use of mcdc CLI tool. The collection of guest level information can be achieved by leveraging SSH for Linux VMs, VMWare tools for both Linux and Windows VMs and WMI for Windows VMs. The collection for each VM includes:
- Uploading the collection script to the VM
- Running the script on the VM
- Downloading and importing the results
The below sample scripts can be used as a reference to get started with collection at scale and it can be enhanced and modified to satisfy your requirements. Below is a brief explanation on each of the scripts:
NOTE: The below bash scripts expect the mcdc
CLI to be present in the shell PATH. Download and installation instructions can be found here and to add the mcdc
binary to the path you can run the command export PATH=$PATH:~/m2c/mcdc
assuming that the binary is placed in the ~/m2c/mcdc
directory.
- mcdc_discovery_export_guest_tools.sh - This scripts creates a CSV file with the following fields
NAME;PLATFORM VM ID;OS Family;IP;USERNAME;PASSWORD
. Note that USERNAME and PASSWORD will always be empty and can be modified manually to set a unique USERNAME and PASSWORD for guest collection using one of the below scripts. See a sample CSV at sample_vms.csv. The output of this script can be used as an input to the script mcdc_collect_vms_guest_tools.sh - mcdc_win_discovery_export_guest_tools.ps1 - This script can be used when running mcdc CLI on a Windows workstation. It creates a CSV file named vms.csv with the following fields
NAME;PLATFORM VM ID;OS Family;IP;USERNAME;PASSWORD
. Note that USERNAME and PASSWORD will always be empty and can be modified manually to set a unique USERNAME and PASSWORD for guest collection using one of the below scripts. See a sample CSV at sample_vms.csv. The output of this script can be used as an input to the script mcdc_win_collect_vms_guest_tools.ps1 - mcdc_discovery_export_ssh.sh - This scripts creates a CSV file with the following fields
NAME;PLATFORM VM ID;OS Family;IP;USERNAME;PASSWORD
. Note that USERNAME and PASSWORD will always be empty and can be modified manually to set a unique USERNAME and PASSWORD for guest collection using one of the below scripts. See a sample CSV at sample_vms.csv. The output of this script can be used as an input to the scripts mcdc_collect_vms_ssh_password.sh and mcdc_collect_vms_ssh_key.sh - mcdc_collect_vms_ssh_password.sh - This script prompts the user for a CSV_FILE(in the format above),USERNAME and PASSWORD and will iterate over all VMs in the CSV file to run the collection script on each Linux VM via SSH using username/password authentication. If a VM has different credentials it can be set in the CSV file per VM.
- mcdc_collect_vms_ssh_key.sh - This script prompts the user for a CSV_FILE and a USERNAME and it will run collection on all the Linux VMs in the CSV file authenticating with SSH key. You must set the environment variable MCDC_SSH_IDENTITY_FILE to the SSH identity file and if needed the MCDC_SSH_PASSPHRASE to the key passphrase.
- mcdc_collect_vms_guest_tools.sh - This script prompts the user for a CSV_FILE(in the format above), VSPHERE_URL, VSPHERE_USER, VSPHERE_PASSWORD, USERNAME and PASSWORD and will iterate over all VMs in the CSV file to run the collection script on each VM(both Linux and Windows) via VMWare tools using username/password authentication. If a VM has different credentials it can be set in the CSV file per VM.
- mcdc_win_collect_vms_guest_tools.ps1 - This script can be used when running mcdc CLI on a Windows workstation. It prompts the user for a CSV_FILE(in the format above), VSPHERE_URL, VSPHERE_USER, VSPHERE_PASSWORD, USERNAME and PASSWORD and will iterate over all VMs in the CSV file to run the collection script on each VM(both Linux and Windows) via VMWare tools using username/password authentication. If a VM has different credentials it can be set in the CSV file per VM.
- mcdc_collect_aws_guest_ssm.sh - This script performs guest collection on all AWS instances connected to SSM using the Session Manager. It requires the session manager plugin to be installed on your local machine. It will call
aws ssm describe-instance-information
to generate a list of VMs to collect. All arguments given to the script are passed directly toaws ssm describe-instance-information
, so you can e.g. set the region by callingmcdc_collect_aws_guest_ssm.sh --region eu-north-1
, or filter to a specific instance by callingmcdc_collect_aws_guest_ssm.sh --filters "Key=InstanceIds,Values=<MY_INSTANCE_ID>"
, as documented here. Note it will silently ignore VMs not connected to SSM. - mcdc_collect_aws_guest_ssh.sh - This script attempts to perform guest collection on all Linux AWS instances using SSH. It uses EC2 instance connect for authentication, and connects to the public IP Address. To pass arguments to SSH pass them using the
--ssh-arg
flag (e.g.mcdc_collect_aws_guest_ssh.sh --ssh-arg '-o StrictHostKeyChecking=no'
). All other args are passed directly toaws ec2 describe-instances
, so you can e.g. set the region by callingmcdc_collect_aws_guest_ssh.sh --region eu-north-1
, or filter to a specific instance by callingmcdc_collect_aws_guest_ssh.sh --instance-ids <MY_INSTANCE_ID>
, as documented here. The script can be easily modified to e.g. connect to private IP addresses, or use sshpass to authenticate. To read more about mcdc cli please look at the formal documentation here