Skip to content
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 azure service principal using ansible #87

Open
anikm1987 opened this issue Apr 16, 2021 · 0 comments
Open

Unable to create azure service principal using ansible #87

anikm1987 opened this issue Apr 16, 2021 · 0 comments

Comments

@anikm1987
Copy link

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ X] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Below ansible file I have used to create service principal and setting the password. I am getting error


  • hosts: localhost
    connection: local
    vars:
    azure_app_id: "123456"
    tasks:
    • name: Generate password
      set_fact:
      password: "{{ azure_app_id | password_hash('sha512') }}"
      tenant_id: "{{ lookup('env', 'AZURE_TENANT') }}"
      azure_client_id: "{{ lookup('env', 'AZURE_CLIENT_ID') }}"

      • name: Create app Service Principal
        azure.azcollection.azure_rm_adserviceprincipal:
        app_id: "{{ azure_app_id }}"
        state: present
        tenant: "{{ tenant_id }}"
        register: azure_output
        environment:
        AZURE_SUBSCRIPTION_ID: "{{ subscription_id }}"

      • name: Set SPN password
        azure.azcollection.azure_rm_adpassword:
        app_id: "{{ azure_app_id }}"
        service_principal_object_id: "{{ azure_output.object_id }}"
        state: present
        value: "{{ password }}"
        environment:
        AZURE_SUBSCRIPTION_ID: "{{ subscription_id }}"

      • debug:
        var: azure_output

Any log messages given by the failure

Command to execute -
ansible-playbook test.yml --extra-vars "subscription_id=<subscription_id>"

The full traceback is:
File "/tmp/ansible_azure.azcollection.azure_rm_adserviceprincipal_payload_jo7iajtw/ansible_azure.azcollection.azure_rm_adserviceprincipal_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_adserviceprincipal.py", line 153, in create_resource
File "/home/ubuntu/.local/lib/python3.8/site-packages/azure/graphrbac/operations/service_principals_operations.py", line 87, in create
raise models.GraphErrorException(self._deserialize, response)
fatal: [localhost]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"ad_user": null,
"adfs_authority_url": null,
"api_profile": "latest",
"app_id": "123456",
"app_role_assignment_required": null,
"auth_source": "auto",
"cert_validation_mode": null,
"client_id": null,
"cloud_environment": "AzureCloud",
"password": null,
"profile": null,
"secret": null,
"state": "present",
"subscription_id": null,
"tenant": ""
}
},
"msg": "Error creating service principle, app id 123456 - Access Token missing or malformed."
}

Expected/desired behavior

Service principal should gets created

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)

Ubuntu

Release: 20.04
Codename: focal

Versions

ansible 2.9.6
python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]

Mention any other details that might be useful


Thanks! We'll be in touch soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant