Environment Variables

Environment Variables

CONS3RT specific environment variables are set and available to install scripts at runtime to use in Software and Test assets

  • Grab media files from the asset
  • Launch additional code (e.g. Puppet manifests)
  • Set conditional logic based on Role name
  • Grab custom properties or deployment properties

Variables

  • ASSET_DIR: Path to the parent directory of your software asset
    • To access media files in Linux: $ASSET_DIR/media/filename.zip
    • To access media files in Windows Powershell: $env:ASSET_DIR\media\filename.zip
  • CONS3RT_ROLE_NAME: Set to the Role Name given to this System in the Scenario
  • DEPLOYMENT_HOME: Path to the directory containing the deployment properties files

Using Environment Variables

Below\, there are two examples of code where an Environment Variable (In this case CONS3RT_ROLE_NAME) is used to make a single asset more versatile by incorporating branching logic to tie the CONS3RT_ROLE_NAME variable (ie. database) to specific actions (like a triggered yum package).

This code sample is using Powershell

if ("$env:CONS3RT_ROLE_NAME" -like "*spr*") {
    $global:QUADRANT="IMS"
} elseif ("$env:CONS3RT_ROLE_NAME" -like "*hap*") {
    $global:QUADRANT="GATEWAYA"
} elseif ("$env:CONS3RT_ROLE_NAME" -like "*ftc*") {
    $global:QUADRANT="GATEWAYB"
} elseif ("$env:CONS3RT_ROLE_NAME" -like "*Splunk*") {
    $global:QUADRANT="SPLUNK"
} else {
    echo "ERROR: $env:CONS3RT_ROLE_NAME is not a valid role namne"
}

The second code sample is using Bash.

if [[ ${CONS3RT_ROLE_NAME} == "database" ]]; then
    echo "Installing database packages..."
    yum -y install mariadb
elif [[ ${CONS3RT_ROLE_NAME} == "web" ]]; then
    echo "Installing web server packages..."
    yum -y install httpd
else
    echo "No package install needed for: ${CONS3RT_ROLE_NAME}
fi