Ubuntu控制节点使用microsoft.ad.ldap插件从Active Directory创建动态Inventory失败问题求助
我目前用Ubuntu作为Ansible控制节点,想要从Windows Server 2022域控制器获取主机列表,但官方的LDAP-Inventory指南和microsoft.ad.ldap库存插件文档说明不够详细,折腾了很久还是没解决问题,想请教各位大佬帮忙排查。
我的操作流程
- 先后创建了两个库存配置文件:
inventory.microsoft.ad.yml和inventory.microsoft.ad.ldap.yml,文件内容一致,如下:
plugin: microsoft.ad.ldap server: ldap://example.domain.com base_dn: dc=example,dc=com bind_dn: cn=Administrator,cn=Users,dc=example,dc=com bind_password: admin_pass query_filter: (objectClass=computer)
- 执行测试命令:
ansible-inventory -i /etc/ansible/inventory.microsoft.ad.yml --list
出现的错误信息
[WARNING]: * Failed to parse /etc/ansible/inventory.microsoft.ad.yml with auto plugin: inventory config '/etc/ansible/inventory.microsoft.ad.yml' specifies unknown plugin 'microsoft.ad.ldap'
[WARNING]: * Failed to parse /etc/ansible/inventory.microsoft.ad.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory
[WARNING]: * Failed to parse /etc/ansible/inventory.microsoft.ad.yml with ini plugin: Invalid host pattern 'plugin:' supplied, ending in ':' is not allowed, this character is reserved to provide a port.
[WARNING]: Unable to parse /etc/ansible/inventory.microsoft.ad.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
已完成的排查工作
- 验证
microsoft.ad集合已安装:通过ansible-galaxy collection list命令确认过集合存在 - 安装了文档要求的所有依赖包:
- dnspython
- pyspnego >= 0.8.0
- pyspnego[kerberos]
- sansldap
- 网上查了大量资料,发现大部分内容都是关于云提供商的动态Inventory配置,几乎找不到针对Microsoft AD的完整配置步骤;还有部分用户提到需要编写Python脚本实现,但官方文档里并没有提及这一点,我也不确定到底是仅用插件即可,还是必须额外编写脚本。
实在搞不懂为什么会提示“unknown plugin 'microsoft.ad.ldap'”,明明官方文档里明确使用了这个插件名称,希望有经验的朋友能指点问题所在,或者提供一个完整的配置流程参考,非常感谢!
备注:内容来源于stack exchange,提问作者AMM

