Ansible vs. multiple Azure subscriptions

Hi,

I have Azure with multiple subscriptions and I wonder what's the best
way to switch between them. The main two methods described in docs
are:
- password, but I don't see a way to distinguish subscription
- service principal, I still trying to figure out if I can use the
same SP in many subscriptions.

How do you deal with this?

Wawrzek

Link to docs:
https://docs.ansible.com/ansible/latest/scenario_guides/guide_azure.html#providing-credentials-to-azure-modules

Not sure how you deal but for me Azure CLI az login works best, login and just choose current subscription which you want to work on. Just change the current default subscription. Did you try with this approach? I liked this one. From memory, I don’t think I created Service Principal for Ansible but yes for Terraform.

Ameya

Hi,

Perhaps, you can use environment to pass the good variables to the relevant parts of your playbooks :
https://docs.ansible.com/ansible/latest/user_guide/playbooks_environment.html

Regards,

JYL

[...]

I have Azure with multiple subscriptions and I wonder what's the best
way to switch between them.

[...]

How do you deal with this?

Not sure how you deal but for me Azure CLI az login works best, login and just choose current subscription which you want to work on. Just change the current default subscription. Did you try with this approach? I liked this one. From memory, I don't think I created Service Principal for Ansible but yes for Terraform.

Thanks for suggestions. For now, I added my SP to another
subscription. Now can switch between them using `AZURE_PROFILE`
environment variable. A powerful (and scary) thing is that I can have
two different subscriptions in two different shells.

Thanks,
Wawrzek

I’d love to hear more about this. Are you saying that you’re able to authenticate and run playbooks to Azure just by using your az login session? No Service principle at all?