# Need help creating an Azure service principal for ansible. Redirect URI for ansible ?

**URL:** <https://forum.ansible.com/t/need-help-creating-an-azure-service-principal-for-ansible-redirect-uri-for-ansible/23299>\
**Category:** Ansible Project\
**Tags:** azure, ubuntu\
**Created:** [December 20, 2016, 9:39pm UTC](https://forum.ansible.com/t/need-help-creating-an-azure-service-principal-for-ansible-redirect-uri-for-ansible/23299 "2016-12-20T21:39:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prasanna\_Dhandapani](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@Prasanna\_Dhandapani](https://forum.ansible.com/u/Prasanna_Dhandapani)\
**Post date:** [December 20, 2016, 9:39pm UTC](https://forum.ansible.com/t/need-help-creating-an-azure-service-principal-for-ansible-redirect-uri-for-ansible/23299/1 "2016-12-20T21:39:24Z")

</div>

Hello, I’m new to Ansible and I’m running into an issue with getting the “azure\_rm\_storageaccount” module in ansible to work. Any help would be greatly appreciated.

Goal: I would like to manage our Azure resources in our sandbox environment using Ansible playbook. I installed Azure CLI on my Ansible control node (Ubuntu 16.10) and I can execute CLI commands to create/delete resources in Azure. I want to do the same via playbooks.

This is my playbook yml file.

- hosts: localhost  
become: yes  
become\_method: sudo  
tasks:
- name: Create storage account  
azure\_rm\_storageaccount:  
resource\_group: test-rg  
subscription\_id:   
name: test\_storage\_account  
account\_type: Standard\_LRS  
ad\_user: [abc@xxx.com](mailto:abc@xxx.com)  
password:\*\*\*\*  
state: present

When I run the playbook, I get the error below

fatal: [localhost]: FAILED! =\> {“changed”: false, “failed”: true, “module\_stderr”: “”, “module\_stdout”: "Traceback (most recent call last):\r\n File "/tmp/ansible\_kfOrUg/ansible\_module\_azure\_rm\_storageaccount.py", line 442, in \r\n main()\r\n File "/tmp/ansible\_kfOrUg/ansible\_module\_azure\_rm\_storageaccount.py", line 439, in main\r\n AzureRMStorageAccount()\r\n File "/tmp/ansible\_kfOrUg/ansible\_module\_azure\_rm\_storageaccount.py", line 200, in **init** \r\n supports\_check\_mode=True)\r\n File "/tmp/ansible\_kfOrUg/ansible\_modlib.zip/ansible/module\_utils/azure\_rm\_common.py", line 183, in **init** \r\n File "/usr/local/lib/python2.7/dist-packages/msrestazure/azure\_active\_directory.py", line 335, in **init** \r\n self.set\_token()\r\n File "/usr/local/lib/python2.7/dist-packages/msrestazure/azure\_active\_directory.py", line 370, in set\_token\r\n raise\_with\_traceback(AuthenticationError, "", err)\r\n File "/usr/local/lib/python2.7/dist-packages/msrest/exceptions.py", line 50, in raise\_with\_traceback\r\n raise error\r\nmsrest.exceptions.AuthenticationError: , InvalidGrantError: (invalid\_grant)

AADSTS70002: Error validating credentials. AADSTS50126: Invalid username or password\r\r\nTrace ID: 7e573a6f-cbaf-4fab-89a9-f6154a509f9b\r\r\nCorrelation ID: a123d9d0-9d96-4aa4-a2aa-5dfaaef245e8\r\r\nTimestamp: 2016-12-20 21:27:53Z\r\n", “msg”: “MODULE FAILURE”, “parsed”: false}

I have the following env variables defined:

AZURE\_AD\_USER  
AZURE\_PASSWORD  
AZURE\_SUBSCRIPTION\_ID

Ansible documentation states if I use AAD to authenticate to Azure, MFA should be disabled for the account. In my case, MFA is enabled, that’s probably what is causing the above error.

The recommendation for authentication seems to be to create a Service Principal. Steps are as below:

1: Login to the Azure Portal (Not Classic)  
2: Go to Azure Active Directory → App Registrations  
3: Add  
4: Entered Name and chose Native for Application Type (Since I’m using Ansible command line (not Tower), I guess I should choose Native? )  
5: It asks for Redirect URI

I am not sure what the Redirect URI should be ? Where do I find this ?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![juchausse](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@juchausse](https://forum.ansible.com/u/juchausse)\
**Post date:** [March 1, 2017, 2:52pm UTC](https://forum.ansible.com/t/need-help-creating-an-azure-service-principal-for-ansible-redirect-uri-for-ansible/23299/2 "2017-03-01T14:52:07Z")

</div>

Hi there,

Did you get any update about the information you are looking for ?

Cheers  
Julien
