1
votes

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?

2
I cant able to use sudo in the first place, also i want to spinoff around 50 vm, So i cant ssh into each machines. - Selva
I've checked the log. I've put "whoami" in the script and saw the output. the user is "_azbatch" - Selva

2 Answers

1
votes

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.

-1
votes

According to your description, based on my understanding, you want to install the same packages on Azure Linux VM created in bulk by Azure Batch Services.

Per my experience, I think you can manually do these installation concurrently on all machines via some parallel SSH tools like pssh, orgalorg, Parallec, erlyssh, etc. It's a workaround way. Some python packages need compiler support while installing, so I think manual operation maybe a better choice under uncertainty.

Hope it helps.