azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

Installation of Azure CLI from shell script: "bash: line 42: /dev/tty: No such device or address"

Open JoeShabadu2000 opened this issue 3 years ago • 1 comments

Describe the bug

I am trying to install Azure CLI on an Ubuntu 22.04 VM in Azure, as part of a Custom Script Extension for Linux setup script. I have had this running fine in the past, but now it no longer seems to install properly.

Following the instructions for Installing AZ CLI as part of a script I have the following line as part of my setup script:

curl -L https://aka.ms/InstallAzureCli | bash

Whenever my script gets to this portion, I receive the following output:

Enable succeeded: 
[stdout]
Downloading Azure CLI install script from https://azurecliprod.blob.core.windows.net/install.py to /tmp/azure_cli_install_tmp_Dbp6Dd.
/tmp/azure_cli_install_tmp_Dbp6Dd: OK
Running install script.

[stderr]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  1405  100  1405    0     0   1873      0 --:--:-- --:--:-- --:--:-- 20071
#=#=#                                                                         
##O#-#                                                                        

######################################################################## 100.0%
bash: line 42: /dev/tty: No such device or address

From what I can tell, the install script is being downloaded properly, so no issues with networking I don't think. I looked at the install file that gets downloaded, and line 42 references "$python_cmd $install_script < $_TTY" so it seems like that may be related to this issue.

I have cut down my install script so that the only command in it is the AZ CLI setup command, but get the same error, so I don't think it is anything related to elsewhere in my script. I have also tried running the AZ CLI Installer command directly from the Custom Script Extension (without including it in a separate .sh file) and get the same error.

Additionally, when I try to run the setup command inside of the "Run Command Script" shell extension on an existing VM running Ubuntu 22.04, I get the same error. This makes me think it isn't related to my Custom Script Extension setup, but rather something about installing AZ CLI as part of a script with no user input.

When I run the AZ CLI setup command after logging in through SSH, everything works fine. But I do get a few prompts about where AZ CLI should be installed, etc. I didn't see anything on the install page about switches to disable these prompts, maybe this is the issue?

To Reproduce

Create an Ubuntu 22.04 VM in Azure with a standard VNET, subnet, and public IP. In the Azure Portal, select the VM, then go to Operations -> Run Command -> RunShellScript. Enter the following command:

curl -L https://aka.ms/InstallAzureCli | bash

Expected behavior

I expected AZ CLI to be installed and for the az set of commands to be available for use to any user upon their next login. As I mentioned, this has worked fine for me in the past, but not today.

Thanks very much for any help!

JoeShabadu2000 avatar Aug 12 '22 17:08 JoeShabadu2000

@jiasli for awareness

yonzhan avatar Aug 12 '22 22:08 yonzhan

https://aka.ms/InstallAzureCli from https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=script is for interactive installation from PyPI. Since you are using "Custom Script Extension", I think it doesn't have a TTY, so the error happens.

I guess previously you are installing with https://aka.ms/InstallAzureCLIDeb from https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt ? That script installs Azure CLI DEB package and doesn't require any interactive intervention. This is also the recommended way of installing Azure CLI on Ubuntu/Debian.

jiasli avatar Aug 24 '22 03:08 jiasli

Yes, that seems to have been my problem! Thanks very much for taking the time to reply.

JoeShabadu2000 avatar Aug 24 '22 11:08 JoeShabadu2000