Recently I’ve been working on an automation project with a focus on the Application Services part of vRealize Automation. With Application Services you can automate application deployment; from simple single-tier applications to multi-tier application whether or not combined with on-demand networking components. A populair example of a vRA multi-tier application is the WordPress 3 tier application available on code.vmware.com.
While working with Application Services I sometimes noticed that some bash scripts, in some cases provided by an external vendor, failed when executed as a software component in vRA. The script ran without any problem when executed in a normal user session. So, apparently there’s some difference between running a script/software component in a ‘normal’ user session versus running the script in the context of the vRA agent. So the question was, what is the difference?
To dive a little deeper into this I both executed the ‘set’ command. The set command in Linux provides your with information on environment variables. In the post I’ve included the environment variables that are specific in the vRA guest agent context:
APPD_RUN_IDENTIFIER=0f427741-c52e-47ed-88b5-917e6c8b69bf BASH_EXECUTION_STRING='chmod go-rwx /tmp/0f427741-c52e-47ed-88b5-917e6c8b69bf;source /tmp/0f427741-c52e-47ed-88b5-917e6c8b69bf/script.sh /tmp/0f427741-c52e-47ed-88b5-917e6c8b69bf/task.sh /tmp/0f427741-c52e-47ed-88b5-917e6c8b69bf/output.properties > /tmp/0f427741-c52e-47ed-88b5-917e6c8b69bf/task.stdlog 2>&1' BASH_LINENO=([0]="286" [1]="0") BASH_SOURCE=([0]="/tmp/0f427741-c52e-47ed-88b5-917e6c8b69bf/task.sh" [1]="/tmp/0f427741-c52e-47ed-88b5-917e6c8b69bf/script.sh") PATH=/usr/local/bin:/usr/bin
As you can see, Application Services leverages original Application Director (APPD) components, the former name of Application Services. The BASH_EXECUTION_STRING variable points to the script that the vRA guest agent will execute. More interesting is it to have a look at the PATH variable. The vRA guest agent uses the root account to run the script, but the PATH variable doesn’t look like the normal PATH variable for root:
PATH=/sbin:/bin:/usr/sbin:/usr/bin
As you can see we’re missing the /sbin, /bin and /usr/sbin folders here. This means that command that are in these folders will not work if the path is not exclusively mentioned in the command. Take a look in these folders to see what commands are there. This can be a reason that certain bash scripts don’t work as expected. To solve this issue you can add the required paths to the PATH variable:
PATH=$PATH:/sbin
…to add the sbin folder (as an example). This hopefully will help to make your script work!