# Azure service principle

**URL:** <https://forum.ansible.com/t/azure-service-principle/5903>\
**Category:** Get Help\
**Tags:** azure, windows\
**Created:** [May 21, 2024, 8:21am UTC](https://forum.ansible.com/t/azure-service-principle/5903 "2024-05-21T08:21:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Martin](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/paul_martin/32/3498_2.png) [@Paul\_Martin](https://forum.ansible.com/u/Paul_Martin)\
**Post date:** [May 21, 2024, 8:21am UTC](https://forum.ansible.com/t/azure-service-principle/5903/1 "2024-05-21T08:21:31Z")

</div>

Sorry if this has already been covered elsewhere. Not sure if the following is possible, but would appreciate any assistance people could provide.

Environment: Azure  
Hosts : Linux and Windows.

Can i connect to the OS of the hosts (via SSH or WinRM) using a service principle or Azure managed identity? i plan on giving the service principle or managed identity the “Virtual Machine Administrator Login” role to then allow the relevant playbooks to be run.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [May 21, 2024, 2:26pm UTC](https://forum.ansible.com/t/azure-service-principle/5903/2 "2024-05-21T14:26:19Z")

</div>

I don’t have any experience with Azure, but Microsoft does have documentation for using Ansible with Azure. It looks like the short answer is “yes” you can use service principles for Ansible in Azure.

Things you’ll be interested in:

1. [Get Started - Configure Ansible using Azure Cloud Shell | Microsoft Learn](https://learn.microsoft.com/en-us/azure/developer/ansible/getting-started-cloud-shell?tabs=ansible)
2. [Get Started - Configure Ansible on an Azure VM | Microsoft Learn](https://learn.microsoft.com/en-us/azure/developer/ansible/install-on-linux-vm?tabs=azure-cli)
3. [Quickstart - Create an Azure service principal for Ansible | Microsoft Learn](https://learn.microsoft.com/en-us/azure/developer/ansible/create-ansible-service-principal?tabs=azure-cli)
4. [Tutorial - Configure dynamic inventories for Azure Virtual Machines using Ansible | Microsoft Learn](https://learn.microsoft.com/en-us/azure/developer/ansible/dynamic-inventory-configure?tabs=azure-cli)
5. [Azure.Azcollection — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/collections/azure/azcollection/index.html)

---

<div class="post-metadata">

**Author:** ![Paul\_Martin](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/paul_martin/32/3498_2.png) [@Paul\_Martin](https://forum.ansible.com/u/Paul_Martin)\
**Post date:** [May 21, 2024, 3:32pm UTC](https://forum.ansible.com/t/azure-service-principle/5903/3 "2024-05-21T15:32:49Z")

</div>

Thanks for the reply.

Looking at the links you provided, they appear to be more related to creating and managing azure resources using ansible with the service principle.

I am hoping it is possible to connect to the vm via ssh or winrm using the service principle using something like the anisble\_user and/or ansible\_password variables.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [May 21, 2024, 3:47pm UTC](https://forum.ansible.com/t/azure-service-principle/5903/4 "2024-05-21T15:47:49Z")

</div>

This is an older link, and is more about enabling the dynamic inventory with Azure managed identities, but they are pinging hosts as part of the demo after enabling the dynamic inventory.

[Configure Ansible to use a Managed Identity with Azure Dynamic Inventory - Microsoft Community Hub](https://techcommunity.microsoft.com/t5/core-infrastructure-and-security/configure-ansible-to-use-a-managed-identity-with-azure-dynamic/ba-p/1062449)

So, they _might_ be using MSI for authenticating to inventory, but then the configuration docs from Microsoft seem to imply that you need to configure SSH keys or password auth for VM’s.

- Linux  
[Create a Linux virtual machines in Azure using Ansible | Microsoft Learn](https://learn.microsoft.com/en-us/azure/developer/ansible/vm-configure?tabs=ansible)
- Windows  
[Create a Windows virtual machine in Azure using Ansible | Microsoft Learn](https://learn.microsoft.com/en-us/azure/developer/ansible/vm-configure-windows?tabs=ansible)
