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

Add new module for AD Users #402

Merged
merged 32 commits into from
Apr 19, 2021
Merged

Add new module for AD Users #402

merged 32 commits into from
Apr 19, 2021

Conversation

coleneubauer
Copy link
Contributor

@coleneubauer coleneubauer commented Jan 21, 2021

SUMMARY

Addition of a module to return ad user information and create, update, or delete a user.

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

azure_rm_aduser_info

ADDITIONAL INFORMATION

This is the addition of a new module. The module supports getting information for an AD user or multiple users. The module supports multiple parameters for defining the scope of users to return as well as a direct OData filter for more complex queries.

Before a playbook with the following would fail because the module did not exist.
    - name: Using user_principle_name
      azure.azcollection.azure_rm_aduser_info:
        user_principle_name: user@contoso.com
        tenant: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

    - name: Using object_id
      azure.azcollection.azure_rm_aduser_info:
        object_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
        tenant: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

    - name: Using attribute mailNickname - not a collection
      azure.azcollection.azure_rm_aduser_info:
        attribute_name: mailNickname
        attribute_value: users_mailNickname
        tenant: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

    - name: Using attribute proxyAddresses - a collection
      azure.azcollection.azure_rm_aduser_info:
        attribute_name: proxyAddresses
        attribute_value: SMTP:user@contoso.com
        tenant: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

    - name: Using Filter mailNickname
      azure.azcollection.azure_rm_aduser_info:
        odata_filter: mailNickname eq 'user@contoso.com'
        tenant: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

    - name: Using Filter proxyAddresses
      azure.azcollection.azure_rm_aduser_info:
        odata_filter: proxyAddresses/any(c:c eq 'SMTP:user@contoso.com')
        tenant: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

With valid parameters, the playbook would now return information of the users who fit the scope defined.

@Fred-sun
Copy link
Collaborator

@coleneubauer Thank you for your contribution. This module is used to retrieve the Azure Recovery Services Vault policy. Can you add a module to manage the Azure Recovery Services Vault policy (azure_rm_aduser.py)? Use to implement the creation and deletion of a service library backup policy. Thank you very much!

@Fred-sun Fred-sun added medium_priority Medium priority new_module_pr Add new modules work in In trying to solve, or in working with contributors ready_for_review The PR has been modified and can be reviewed and merged and removed ready_for_review The PR has been modified and can be reviewed and merged labels Jan 25, 2021
@coleneubauer
Copy link
Contributor Author

coleneubauer commented Jan 25, 2021

@coleneubauer Thank you for your contribution. This module is used to retrieve the Azure Recovery Services Vault policy. Can you add a module to manage the Azure Recovery Services Vault policy (azure_rm_aduser.py)? Use to implement the creation and deletion of a service library backup policy. Thank you very much!

@Fred-sun I think you may have mixed up my PRs. This is unrelated to the Azure Recovery Services Vault Backup Policy. That PR has both an info module and a management module. This one only is an info module to read AD User account information. I don't have a current business need for the management module and would like to not write it at this time.

Copy link
Collaborator

@Fred-sun Fred-sun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coleneubauer Add a use case that successfully gets the AdUser information to the use case. Thank you very much!

tests/integration/targets/azure_rm_aduser/tasks/main.yml Outdated Show resolved Hide resolved
coleneubauer and others added 4 commits February 9, 2021 16:15
Co-authored-by: Fred-sun <37327967+Fred-sun@users.noreply.github.com>
Co-authored-by: Fred-sun <37327967+Fred-sun@users.noreply.github.com>
@coleneubauer coleneubauer changed the title Add new module to get information on AD users Add new module for AD Users Feb 17, 2021
@coleneubauer
Copy link
Contributor Author

@Fred-sun The additional module has been added as requested.

@Fred-sun
Copy link
Collaborator

@coleneubauer Thanks for your update! I will test and push for merge!

@coleneubauer
Copy link
Contributor Author

@haiyuazhang The metadata blocks have been removed.

coleneubauer and others added 3 commits March 8, 2021 15:17
Co-authored-by: Fred-sun <37327967+Fred-sun@users.noreply.github.com>
add space after commit from reviewer suggeststion
add space after commit from reviewer suggeststion
@coleneubauer
Copy link
Contributor Author

@Fred-sun The metaclass line was added as suggested

@Fred-sun
Copy link
Collaborator

@Fred-sun The metaclass line was added as suggested

@coleneubauer Do you execute your tests/integration/the targets/azure_rm_aduser/tasks/main.yml? Can you share your test results? Thank you very much!

@coleneubauer
Copy link
Contributor Author

@Fred-sun The metaclass line was added as suggested

@coleneubauer Do you execute your tests/integration/the targets/azure_rm_aduser/tasks/main.yml? Can you share your test results? Thank you very much!

@Fred-sun I don't know how to execute the tests directly. I could not find in documentation how this was done and made the assumption this was intentional. What I do for the tests is copy the test to a local playbook, write a task at the top defining existing vars, and run the playbook. When I do it this way the results are that all the tasks pass.

@haiyuazhang
Copy link
Contributor

The convention for a single ansible module is to manage a single resource instance. I checked your "CRUD" functions, seems they also support batch mode. It's bettor to fallback to the normal one module one resource instance way. Besides, The idempotency test is absent in the tests. I test the idempotency of the module locally, it doesn't work.

@coleneubauer
Copy link
Contributor Author

The convention for a single ansible module is to manage a single resource instance. I checked your "CRUD" functions, seems they also support batch mode. It's bettor to fallback to the normal one module one resource instance way. Besides, The idempotency test is absent in the tests. I test the idempotency of the module locally, it doesn't work.

@haiyuazhang
"Besides, The idempotency test is absent in the tests. I test the idempotency of the module locally, it doesn't work."
This is a clear oversight on my part. Thanks for catching it, I'll update to fix.

"The convention for a single ansible module is to manage a single resource instance. I checked your "CRUD" functions, seems they also support batch mode. It's bettor to fallback to the normal one module one resource instance way"
This would be easy to change but it seems like a common use case for ad users to want to change multiple at a time. The alternate is to get a list of user's in ansible and update each one in a loop individually. I think allowing them to directly edit multiple would be more concise. What's your thought on the option of adding a flag to indicate a batch alteration should be done so it's more clear? Either way you want to take it I can update though. Let me know your thoughts, thanks.

@haiyuazhang
Copy link
Contributor

The convention for a single ansible module is to manage a single resource instance. I checked your "CRUD" functions, seems they also support batch mode. It's bettor to fallback to the normal one module one resource instance way. Besides, The idempotency test is absent in the tests. I test the idempotency of the module locally, it doesn't work.

@haiyuazhang
"Besides, The idempotency test is absent in the tests. I test the idempotency of the module locally, it doesn't work."
This is a clear oversight on my part. Thanks for catching it, I'll update to fix.

"The convention for a single ansible module is to manage a single resource instance. I checked your "CRUD" functions, seems they also support batch mode. It's bettor to fallback to the normal one module one resource instance way"
This would be easy to change but it seems like a common use case for ad users to want to change multiple at a time. The alternate is to get a list of user's in ansible and update each one in a loop individually. I think allowing them to directly edit multiple would be more concise. What's your thought on the option of adding a flag to indicate a batch alteration should be done so it's more clear? Either way you want to take it I can update though. Let me know your thoughts, thanks.

If it won't take you too much effort, I suggest that we remove batch support from the module. Since simple loop in playbook can serve the same purpose. Keeping "the style" consistent among the modules in this collection might be a good practice.

@coleneubauer
Copy link
Contributor Author

The convention for a single ansible module is to manage a single resource instance. I checked your "CRUD" functions, seems they also support batch mode. It's bettor to fallback to the normal one module one resource instance way. Besides, The idempotency test is absent in the tests. I test the idempotency of the module locally, it doesn't work.

@haiyuazhang
"Besides, The idempotency test is absent in the tests. I test the idempotency of the module locally, it doesn't work."
This is a clear oversight on my part. Thanks for catching it, I'll update to fix.
"The convention for a single ansible module is to manage a single resource instance. I checked your "CRUD" functions, seems they also support batch mode. It's bettor to fallback to the normal one module one resource instance way"
This would be easy to change but it seems like a common use case for ad users to want to change multiple at a time. The alternate is to get a list of user's in ansible and update each one in a loop individually. I think allowing them to directly edit multiple would be more concise. What's your thought on the option of adding a flag to indicate a batch alteration should be done so it's more clear? Either way you want to take it I can update though. Let me know your thoughts, thanks.

If it won't take you too much effort, I suggest that we remove batch support from the module. Since simple loop in playbook can serve the same purpose. Keeping "the style" consistent among the modules in this collection might be a good practice.

Sounds good, thanks for the feedback. I should be able to update this sometime this week.

@coleneubauer
Copy link
Contributor Author

coleneubauer commented Mar 31, 2021

@Fred-sun @haiyuazhang Updated as requested and ready for review.

The ad_user module now only will operate on a single account. The info module does allow the users to retrieve information on multiple users as this seems consistent with other info modules see https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_resourcegroup_info_module.html#ansible-collections-azure-azcollection-azure-rm-resourcegroup-info-module or https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_subscription_info_module.html#ansible-collections-azure-azcollection-azure-rm-subscription-info-module or
https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_webapp_info_module.html#ansible-collections-azure-azcollection-azure-rm-webapp-info-module

There's a check now when attempting to update an existing account for idempotency and a test is added in the automated tests to check that an attempted update with no changes should come back as unchanged.

@haiyuazhang haiyuazhang merged commit 6ad65e7 into ansible-collections:dev Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium_priority Medium priority new_module_pr Add new modules work in In trying to solve, or in working with contributors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants