I'm trying to use Azure batch services by creating linux vm. I have some computations for which I'm using python.To install some python packages, I have placed the install commands in script file and try to run that in startup.
pool.StartTask = new StartTask
{
// Specify a command line for the StartTask that copies the task application files to th
CommandLine = "bash -c \"bash /mnt/batch/tasks/startup/wd/installpackages.sh\"",
ResourceFiles = resourceFiles,
WaitForSuccess = true,
MaxTaskRetryCount = 5
};
This script execution fails due to permission problems. When i try to run script with "sudo", the following error occurs,
sudo: no tty present and no askpass program specified
The script is executed by the user "_azbatch" and on using sudo, it prompts for password which I don't know.
How to overcome this?
If you are using Azure Batch C# SDK 6.0.0 or higher (or Azure Batch Python SDK 2.0.0 or higher), you will need to specify a proper UserIdentity
in the StartTask
object.
pool.StartTask.UserIdentity = new UserIdentity(
new AutoUserSpecification(
scope: AutoUserScope.Pool,
elevationLevel: ElevationLevel.Admin
)
)
If you are using a prior SDK version to those mentioned above, you will need to set the StartTask
object RunElevated
member to true
.
With these options, you should remove sudo
from your scripts as your script will automatically run with superuser or administrative privileges.
One additional note regarding:
/mnt/batch/tasks/startup/wd/installpackages.sh
You should never directly reference the path. You can instead use:
bash -c "bash $AZ_BATCH_TASK_WORKING_DIR/installpackages.sh"
or simply:
bash ./installpackages.sh
You can even remove bash
explicit invocation by adding a proper shebang statement to the top of your shell script and invoking as ./installpackages.sh
.
Batch will set the current working directory to the task's working directory for the command execution. You can view all of the environment variables automatically set by Batch for task execution here.