-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to create service principal in Azure using ansible collection #500
Comments
It looks like you're all over the place in terms of providing credentials for authentication. Are you using a service principal's client and secret, a AD user's name and password, or something else? You should pick one of MSI, az-cli login, environmental variables, or explicit parameter in playbook's task definition, and stick with it exclusively for the entirety of the playbook. |
Hi @paultaiton, I am using service principal to authenticate with Azure. Environment variables are set using below commands - I have not provided credentials in any other place. FYI - Resource group is getting created successfully. Having problem with new service principal creation. |
You should also include your subscription id in the environmental variables if that's the method you're using. I assume you've redacted the AZURE_SECRET value for this post, but are still providing it on your system? |
Hi @paultaiton , ansible-playbook create-azure-rg-vars.yml --extra-vars "subscription_id=<subscription_id>" Subscription id passed as environment variable for each task using - environment: Yes AZURE_SECRET value I have redacted for the post. |
@anikm1987 I personally make use of a variable file (I use host_vars/localhost.yml, but you can use something else ) with vaulted strings for principal_id, principal_secret, tenant_guid, and then pass subscription_guid as an extra-vars. Then I pass --ask-vault-password to my ansible-playbook command. |
For testing purpose I set subscription also as environment variable . export AZURE_CLIENT_ID="<client_id>" Changed the yaml file like below -
Run the command - ansible-playbook create-azure-rg-vars-v1.yml -vvv Still getting the same error TASK [Create app Service Principal] ************************************************************************************************************************ |
It looks like this module is repurposing the "tenant" property that is normally only used for authentication purposes to be used as the target of the AD action. When I created the azure_rm_subscription_info module, I had to create a completely different variable for "id" and not reuse the subscription_id parameter to avoid a conflict. My guess is that having "tenant" defined as a module property is making the code think that it should find the details as parameters and not look at the environment, but I'm not sure what's going on since I'm not familiar with this module's code, and am not an expert on the general authentication process. @Fred-sun and @haiyuazhang are listed as the authors of this module, so hopefully they'll have a better answer for you. My only other suggestion is to pass all of the parameters to the module explicitely: tenant, subscription_id, client_id, secret. |
Thanks @paultaiton Hi @Fred-sun @haiyuazhang ,
This block executed successfully without any error but new service principal creation block failed again. Question reagrding the app_id, the value I mentioned in the yaml var section is just an arbitrary uuid value. Hope that is fine. |
Hi, Further investigation shows below log in the error - File "/home/ubuntu/.local/lib/python3.8/site-packages/azure/graphrbac/models/graph_error_py3.py", line 45, in init\n super(GraphErrorException, self).init(deserialize, response, 'GraphError', *args)\n File "/home/ubuntu/.local/lib/python3.8/site-packages/msrest/exceptions.py", line 184, in init\n response.raise_for_status()\nAttributeError: 'ClientRequest' object has no attribute 'raise_for_status'\n", |
@paultaiton @anikm1987 |
#525 has been merged, This Issue can be closed! Thank you very much! |
SUMMARY
ISSUE TYPE
COMPONENT NAME
azure.azcollection.azure_rm_adserviceprincipal
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
STEPS TO REPRODUCE
Configured environment variables -
export AZURE_CLIENT_ID="<client_id>"
export AZURE_SECRET=""
export AZURE_TENANT="tenant_id"
Then run command -
ansible-playbook create-azure-rg-vars.yml --extra-vars "subscription_id=<subscription_id>"
EXPECTED RESULTS
ansible-playbook create-azure-rg-vars.yml --extra-vars "subscription_id=<subscription_id>" -vvvvv
This should create the resource group and one service principal with password.
ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: