gpt4 book ai didi

azure - 为什么 Azure Cloud Shell 在默认订阅中创建资源组?

转载 作者:行者123 更新时间:2023-12-03 02:32:22 24 4
gpt4 key购买 nike

我使用 Set-AzContextAzure Cloud Shell 中当前 session 的订阅更改为其他订阅如下。但是当我使用 Ansible playbook 创建资源组时在Azure Cloud Shell的同一 session 中,资源组仍然是在默认订阅中创建的,为什么?

Set-AzContext -SubscriptionId "myOtherSubscription"

以上命令成功将订阅从默认更改为 myOtherSubscription 并显示结果如下:

Name                                     Account                         SubscriptionName                Environment                     TenantId
---- ------- ---------------- ----------- --------
Visual Studio Enterprise – MPN (a86c7y8… MSI@51342 Visual Studio Enterprise – MPN AzureCloud 86eafd5a-8ce3-4d0c-981c-8dac1…

然后,我运行了 ansible 命令 ansible-playbook myplaybook_to_create_rg.yml,该命令成功创建了资源组,但仍在默认订阅中,而不是在 myOtherSubscription 内。如图this来自 Microsoft 团队的示例,用于创建资源组的 ansible 代码中没有提到订阅。这意味着它应该在运行 Azure Cloud Shell 的订阅中创建资源组。

最佳答案

您的误解根源在于 Ansible 不知道作为 AzContext 的一部分选择的订阅。你正在工作。您链接的文档证实了这一点:

When working with multiple subscriptions, specify the subscription Ansible uses by exporting the AZURE_SUBSCRIPTION_ID environment variable.

对于 Cloud Shell,可以通过以下两种方法之一来设置 Ansible 根据您的 shell 类型使用哪个订阅:

  • 对于基于 PowerShell 的 Cloud Shell 实例,设置 AZURE_SUBSCRIPTION_ID通过运行在本地范围内的环境变量:

    $env:AZURE_SUBSCRIPTION_ID="<your-subscription-id>"

    ...替换 <your-subscription-id>包含目标 Azure 订阅 ID 的占位符。

  • 对于bash 基于Cloud Shell,您可以使用export关键字来实现相同的效果:

    export AZURE_SUBSCRIPTION_ID="<your-subscription-id>"`

    ...替换 <your-subscription-id>包含目标 Azure 订阅 ID 的占位符。

关于azure - 为什么 Azure Cloud Shell 在默认订阅中创建资源组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64564821/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com