代码之家  ›  专栏  ›  技术社区  ›  bramvdk

Azure DevOps托管的ubuntu代理问题更新应用程序网关

  •  0
  • bramvdk  · 技术社区  · 7 年前

    我使用Terraform部署了一些infra,包括一个应用程序网关。不幸的是,并非所有的设置都可以用terraform设置/更新。所以我有一个shell脚本来更新应用程序网关。

    #!/bin/bash
    SP_ID=${1}
    SP_SECRET=${2}
    TENANT_ID=${3}
    SUBSCRIPTION=${4}
    RG=${5}
    
    az login --service-principal -u ${SP_ID} -p ${SP_SECRET} -t ${TENANT_ID}
    az account set --subscription ${SUBSCRIPTION}
    az account list -o table
    
    # Get the name of the AG
    echo "RG = ${RG}"
    AG=$(az network application-gateway list --resource-group ${RG} | tail -n 1 | awk '{ print $2 }')
    echo "AG = ${AG}"
    
    # Get the AG backend pool name
    BP=$(az network application-gateway address-pool list --resource-group ${RG} --gateway-name ${AG} | tail -n 1 | awk '{ print $1 }')
    echo "Backend pool = ${BP}"
    
    # Get the frontendip of the load balancer
    LB=$(az network lb list --resource-group ${RG} | tail -n 1 | awk '{ print $2         }')
    LBFEIP=$(az network lb frontend-ip list --lb-name ${LB} --resource-group    ${RG} | tail -n 1 | awk '{ print $2 }')
    echo "Load balancer = ${LB}"
    echo "Frontend ip LB =  ${LBFEIP}"
    
    # Update the backend pool of the AG with the frontend ip of the loadbalancer
    echo "Updating Backend address pool of AG ${AG}"
    az network application-gateway address-pool update --gateway-name $AG --resource-group $RG --name $BP --servers ${LBFEIP}
    
    # Update http settings
    echo "Updating HTTP settings of AG ${AG}"
    AG_HTS=$(az network application-gateway http-settings list --resource-group     ${RG} --gateway-name ${AG} | tail -n 1 | awk '{ print $2 }')
    az network application-gateway http-settings update --resource-group ${RG} --gateway-name ${AG} --name ${AG_HTS} --host-name-from-backend-pool true
    
    # Update health probe
    echo "Updating Health probe of AG ${AG}"
    AG_HP=$(az network application-gateway probe list --resource-group ${RG} --gateway-name ${AG} | tail -n 1 | awk '{ print $4 }')
    az network application-gateway probe update --resource-group ${RG} --gateway-name ${AG} --name ${AG_HP} --host '' --host-name-from-http-settings true
    

    此脚本在我的笔记本电脑上本地运行时运行正常,但通过azure devops发布管道,我得到错误:

    ERROR: az network application-gateway address-pool list: error: argument --gateway-name: expected one argument
    

    我在WSL Ubuntu上创建了这个脚本,并使用一个Ubuntu托管的代理来发布工件,还使用一个托管的Ubuntu代理来部署脚本。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Charles Xu    7 年前

    这个错误直接说明了问题所在。参数“AG”为空。可以使用CLI命令获取参数“AG”:

    az network application-gateway list -g nancyweb --query "[].name" -o tsv
    

    或者根据您对输出格式表的需要:

    az network application-gateway list -g nancyweb -o table | tail -n 1 | awk '{print $3}'
    

    az network application-gateway list . 但是,如果您想获得特定的网关,有一点您应该注意,因为list命令显示了所有的应用程序网关。