ansible-collections / microsoft.ad

Ansible collection for Active Directory management
GNU General Public License v3.0
36 stars 19 forks source link

Getting an error while running the microsoft.ad module #115

Closed amnibius closed 1 month ago

amnibius commented 1 month ago
SUMMARY

Getting an error while running the microsoft.ad Modules that error occurs: microsoft.ad.user microsoft.ad.group

ISSUE TYPE
COMPONENT NAME

microsoft.ad.group microsoft.ad.user

ANSIBLE VERSION
ansible 2.9.27
  config file = /ansible/microsoft/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.9.18 (main, Feb 17 2024, 05:09:41) [GCC 10.3.1 20210703 (ALT Sisyphus 10.3.1-alt2)]
COLLECTION VERSION
 "collection_info": {
  "namespace": "microsoft",
  "name": "ad",
  "version": "1.5.0",
  "authors": [
   "Jordan Borean @jborean93",
   "Matt Davis @nitzmahone"
  ],
.....
}
CONFIGURATION
ESC[0;33mCOLLECTIONS_PATHS(/ansible/microsoft/ansible.cfg) = ['/ansible/microsoft/collections']ESC[0m
ESC[0;33mDEFAULT_BECOME_FLAGS(/ansible/microsoft/ansible.cfg) = -H -SESC[0m
ESC[0;33mDEFAULT_CALLBACK_WHITELIST(/ansible/microsoft/ansible.cfg) = ['profile_tasks']ESC[0m
ESC[0;33mDEFAULT_FORKS(/ansible/microsoft/ansible.cfg) = 50ESC[0m
ESC[0;33mDEFAULT_GATHERING(/ansible/microsoft/ansible.cfg) = smartESC[0m
ESC[0;33mDEFAULT_HOST_LIST(/ansible/microsoft/ansible.cfg) = ['/ansible/microsoft/inventory']ESC[0m
ESC[0;33mDEFAULT_LOG_PATH(/ansible/microsoft/ansible.cfg) = /ansible/microsoft/logsESC[0m
ESC[0;33mDEFAULT_TIMEOUT(/ansible/microsoft/ansible.cfg) = 60ESC[0m
ESC[0;33mINVENTORY_CACHE_ENABLED(/ansible/microsoft/ansible.cfg) = TrueESC[0m
ESC[0;33mINVENTORY_CACHE_PLUGIN(/ansible/microsoft/ansible.cfg) = jsonfileESC[0m
OS / ENVIRONMENT

Target OS Windows Server 2019 Standard where user or group should be created.

STEPS TO REPRODUCE
- name: Create AD Client Tenant Group
  hosts: ad
  tasks:
    - name: Create Group
      microsoft.ad.group:
        name: Client001
        scope: global
        path: OU=Clients,DC=stg-ost,DC=daas,DC=cloud
        state: present
EXPECTED RESULTS

New group created

ACTUAL RESULTS
ansible-playbook 2.9.27
  config file = /ansible/microsoft/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 3.9.18 (main, Feb 17 2024, 05:09:41) [GCC 10.3.1 20210703 (ALT Sisyphus 10.3.1-alt2)]
Using /ansible/microsoft/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /ansible/microsoft/inventory/hosts as it did not pass its verify_file() method
script declined parsing /ansible/microsoft/inventory/hosts as it did not pass its verify_file() method
auto declined parsing /ansible/microsoft/inventory/hosts as it did not pass its verify_file() method
Parsed /ansible/microsoft/inventory/hosts inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python3/site-packages/ansible/plugins/callback/default.py
Skipping callback 'actionable', as we already have a stdout callback.
Skipping callback 'counter_enabled', as we already have a stdout callback.
Skipping callback 'debug', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'full_skip', as we already have a stdout callback.
Skipping callback 'json', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'null', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
Loading callback plugin profile_tasks of type aggregate, v2.0 from /usr/lib/python3/site-packages/ansible/plugins/callback/profile_tasks.py
Skipping callback 'selective', as we already have a stdout callback.
Skipping callback 'skippy', as we already have a stdout callback.
Skipping callback 'stderr', as we already have a stdout callback.
Skipping callback 'unixy', as we already have a stdout callback.
Skipping callback 'yaml', as we already have a stdout callback.

PLAYBOOK: create-group.yaml **********************************************************************************************************************************
Positional arguments: create-group.yaml
verbosity: 4
connection: smart
timeout: 60
become_method: sudo
tags: ('all',)
inventory: ('/ansible/microsoft/inventory',)
forks: 50
1 plays in create-group.yaml

PLAY [Create AD Client Tenant Group] *************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************
task path: /ansible/microsoft/create-group.yaml:2
Tuesday 21 May 2024  17:18:50 +0300 (0:00:00.026)       0:00:00.026 ***********
Using module file /usr/lib/python3/site-packages/ansible/modules/windows/setup.ps1
Pipelining is enabled.
<10.234.10.10> ESTABLISH WINRM CONNECTION FOR USER: STG-OST.DAAS.CLOUD\ansible on PORT 5985 TO 10.234.10.10
EXEC (via pipeline wrapper)
ok: [10.234.10.10]
META: ran handlers

TASK [Create Group] ******************************************************************************************************************************************
task path: /ansible/microsoft/create-group.yaml:5
Tuesday 21 May 2024  17:18:56 +0300 (0:00:06.322)       0:00:06.349 ***********
Using module file /ansible/microsoft/collections/ansible_collections/microsoft/ad/plugins/modules/group.ps1
Pipelining is enabled.
<10.234.10.10> ESTABLISH WINRM CONNECTION FOR USER: STG-OST.DAAS.CLOUD\ansible on PORT 5985 TO 10.234.10.10
EXEC (via pipeline wrapper)
The full traceback is:
The term 'Invoke-AnsibleADObject' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:211 char:1
+ Invoke-AnsibleADObject @setParams
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Invoke-AnsibleADObject:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CommandNotFoundException

ScriptStackTrace:
at <ScriptBlock>, <No file>: line 211
fatal: [10.234.10.10]: FAILED! => {
    "changed": false,
    "msg": "Unhandled exception while executing module: The term 'Invoke-AnsibleADObject' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."
}

PLAY RECAP ***************************************************************************************************************************************************
10.234.10.10               : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Tuesday 21 May 2024  17:18:59 +0300 (0:00:02.795)       0:00:09.144 ***********
===============================================================================
Gathering Facts --------------------------------------------------------------------------------------------------------------------------------------- 6.32s
/ansible/microsoft/create-group.yaml:2 ----------------------------------------------------------------------------------------------------------------------
Create Group ------------------------------------------------------------------------------------------------------------------------------------------ 2.80s
/ansible/microsoft/create-group.yaml:5 ----------------------------------------------------------------------------------------------------------------------
jborean93 commented 1 month ago

You are running Ansible 2.9 and this collection has a minimum requirement of 2.14 https://github.com/ansible-collections/microsoft.ad?tab=readme-ov-file#ansible-version-compatibility. It is failing because it is loading a module_util using a feature that was introduced in Ansible 2.10 so the cmdlet Invoke-AnsibleADObject from the module util wasn't picked up.

Unfortunately not much you can do about this except for upgrading Ansible to a supported version.