# Ansible vs. multiple Azure subscriptions

**URL:** <https://forum.ansible.com/t/ansible-vs-multiple-azure-subscriptions/29705>\
**Category:** Ansible Project\
**Tags:** azure\
**Created:** [February 19, 2019, 9:46am UTC](https://forum.ansible.com/t/ansible-vs-multiple-azure-subscriptions/29705 "2019-02-19T09:46:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wawrzek\_Niewodniczan](https://avatars.discourse-cdn.com/v4/letter/w/bbe5ce/32.png) [@Wawrzek\_Niewodniczan](https://forum.ansible.com/u/Wawrzek_Niewodniczan)\
**Post date:** [February 19, 2019, 9:46am UTC](https://forum.ansible.com/t/ansible-vs-multiple-azure-subscriptions/29705/1 "2019-02-19T09:46:47Z")

</div>

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](https://docs.ansible.com/ansible/latest/scenario_guides/guide_azure.html#providing-credentials-to-azure-modules)

---

<div class="post-metadata">

**Author:** ![Ameya\_Agashe](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@Ameya\_Agashe](https://forum.ansible.com/u/Ameya_Agashe)\
**Post date:** [February 19, 2019, 11:08am UTC](https://forum.ansible.com/t/ansible-vs-multiple-azure-subscriptions/29705/2 "2019-02-19T11:08:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [February 19, 2019, 11:12am UTC](https://forum.ansible.com/t/ansible-vs-multiple-azure-subscriptions/29705/3 "2019-02-19T11:12:20Z")

</div>

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](https://docs.ansible.com/ansible/latest/user_guide/playbooks_environment.html)

Regards,

JYL

---

<div class="post-metadata">

**Author:** ![Wawrzek\_Niewodniczan](https://avatars.discourse-cdn.com/v4/letter/w/bbe5ce/32.png) [@Wawrzek\_Niewodniczan](https://forum.ansible.com/u/Wawrzek_Niewodniczan)\
**Post date:** [February 19, 2019, 12:19pm UTC](https://forum.ansible.com/t/ansible-vs-multiple-azure-subscriptions/29705/4 "2019-02-19T12:19:49Z")

</div>

[...]

> > 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

---

<div class="post-metadata">

**Author:** ![Steve\_Townsend](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@Steve\_Townsend](https://forum.ansible.com/u/Steve_Townsend)\
**Post date:** [August 9, 2019, 1:56pm UTC](https://forum.ansible.com/t/ansible-vs-multiple-azure-subscriptions/29705/5 "2019-08-09T13:56:29Z")

</div>

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?
