I changed the subscription of the current session in Azure Cloud Shell
to a different subscription using Set-AzContext as follows. But when I create a Resource Group
using Ansible playbook in the same session of Azure Cloud Shell, the resource group is still created in default subscription, why?
Set-AzContext -SubscriptionId "myOtherSubscription"
Above command successfully changed the subscription from default to myOtherSubscription
and showed the result as follows:
Name Account SubscriptionName Environment TenantId
---- ------- ---------------- ----------- --------
Visual Studio Enterprise – MPN (a86c7y8… MSI@51342 Visual Studio Enterprise – MPN AzureCloud 86eafd5a-8ce3-4d0c-981c-8dac1…
Then I ran the the ansible command ansible-playbook myplaybook_to_create_rg.yml
that successfully created the resource group but still in the default subscription instead of inside myOtherSubscription
. As shown in this example from Microsoft team there is no subscription mentioned in the ansible code for creating a resource group. That means it should create the resource group in the subscription that the Azure Cloud Shell in running on.