Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
448 views
in Technique[技术] by (71.8m points)

shell - Create a profile with databricks cli without passing arguments

I am trying to use databricks-cli in a devops pipeline on azure. For that I need to create a profile, using:

databricks configure --profile Profile --token

The problem is that when I run that command, it asks me for host and token which breaks my pipeline waiting for user input. I would like to know if it is possible to do this without passing the arguments.

I already tried this:

echo "configuring databrick-cli authentication"

declare DATABRICKS_URL="https://westeurope.azuredatabricks.net"
declare DATABRICKS_ACCESS_TOKEN="authentication_token_generated_from_databricks_ux"

declare dbconfig=$(<~/.databrickscfg)
if [[ $dbconfig = *"host = "* && $dbconfig = *"token = "* ]]; then
  echo "file [~/.databrickscfg] is already configured"
else
  if [[ -z "$DATABRICKS_URL" || -z "$DATABRICKS_ACCESS_TOKEN" ]]; then
    echo "file [~/.databrickscfg] is not configured, but [DATABRICKS_URL],[DATABRICKS_ACCESS_TOKEN] env vars are not set"
  else
    echo "populating [~/.databrickscfg]"
    > ~/.databrickscfg
    echo "[DEFAULT]" >> ~/.databrickscfg
    echo "host = $DATABRICKS_URL" >> ~/.databrickscfg
    echo "token = $DATABRICKS_ACCESS_TOKEN" >> ~/.databrickscfg
    echo "" >> ~/.databrickscfg
  fi
fi

I am trying to put host and token in databrickscfg but it just hangs in there, I guess it is waiting for the user input again

enter image description here

What am I doing wrong?

question from:https://stackoverflow.com/questions/65889083/create-a-profile-with-databricks-cli-without-passing-arguments

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can achieve that by piping several values at the same time to configure command, like this is done for Databricks Connect here:

echo "$(databricks_host)
    $(databricks_token)" | databricks configure --token

But in reality, you can just use environment variables DATABRICKS_HOST and DATABRICKS_TOKEN as described in documentation - Databricks CLI will pickup them.

The only thing that you need to take into account - that sensitive data like Databricks token need to be stored securely in pipeline definition, and you'll need to access them special way - via env (full definition is here):

    - script: |
        echo "[{{cookiecutter.profile}}]" >> ~/.databrickscfg
        echo "host = $DATABRICKS_HOST" >> ~/.databrickscfg
        echo "token = $DATABRICKS_TOKEN" >> ~/.databrickscfg
      env:
        DATABRICKS_HOST: $(DATABRICKS_HOST)
        DATABRICKS_TOKEN: $(DATABRICKS_TOKEN)

P.S. You can use cicd-templates project to generate a template for Azure DevOps (or for Github Actions) that works out of box with Databricks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...