AWX 20.0(K8s环境)win_chocolatey模块无法识别问题求助
问题:AWX 20.0中
win_chocolatey模块无法识别的修复 环境与问题描述
使用基于Kubernetes的AWX Ansible 20.0版本,编写Playbook通过离线Chocolatey包安装7zip,Playbook代码如下:
--- - name: Install 7zip with offline package chocolatey hosts: all become: true gather_facts: false tasks: - name: Create folder win_file: path: 'C:/Instalki' state: directory - name: Copy installer become: true win_copy: src: "../playbooksWindows/installers/7zip.22.01.nupkg" dest: "C:/Instalki/7zip.22.01.nupkg" - name: install 7zip packages win_chocolatey: name: "7zip" state: present source: "C:/Instalki/7zip.22.01.nupkg" - name : clear folder win_file: path: "C:/Instalki/7zip.22.01.nupkg" state: absent
执行时触发错误:
/usr/local/lib/python3.8/site-packages/paramiko/transport.py:236: CryptographyDeprecationWarning: Blowfish has been deprecated "class": algorithms.Blowfish, No config file found; using defaults SSH password: BECOME password[defaults to SSH password]: ERROR! couldn't resolve module/action 'win_chocolatey'. This often indicates a misspelling, missing collection, or incorrect module path. The error appears to be in '/runner/project/playbooksWindows/Install_7zip.yml': line 27, column 7, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: - name: install 7zip packages ^ here
AWX-EE容器中已安装的集合:
# /usr/share/ansible/collections/ansible_collections Collection Version ----------------------- ------- amazon.aws 4.1.0 ansible.posix 1.4.0 ansible.windows 1.11.1 awx.awx 21.5.0 azure.azcollection 1.13.0 community.vmware 2.9.1 google.cloud 1.0.2 kubernetes.core 2.3.2 openstack.cloud 1.9.1 ovirt.ovirt 2.2.3 redhatinsights.insights 1.0.7 theforeman.foreman 3.6.0 # /home/runner/.ansible/collections/ansible_collections Collection Version --------------------- ------- ansible.windows 1.11.1 chocolatey.chocolatey 1.3.0
已通过ansible-galaxy collection install chocolatey.chocolatey安装集合,且该Playbook在AWX 17.01中可正常运行,需解决此模块识别问题。
修复方案
1. 改用集合全名调用模块
AWX 20.0对集合模块的引用规则更严格,旧版本允许的短模块名(win_chocolatey)在新版本中需要指定完整集合路径。修改Playbook中的模块调用:
- name: install 7zip packages chocolatey.chocolatey.win_chocolatey: name: "7zip" state: present source: "C:/Instalki/7zip.22.01.nupkg"
2. 调整集合安装路径
AWX的runner用户可能无法读取用户级路径(/home/runner/.ansible/collections)的集合,需将chocolatey.chocolatey安装到系统级集合路径:
ansible-galaxy collection install chocolatey.chocolatey -p /usr/share/ansible/collections
3. 在Playbook中声明集合依赖
在Playbook开头添加集合声明,让Ansible自动从指定集合加载模块,无需每次写全名:
--- - name: Install 7zip with offline package chocolatey hosts: all become: true gather_facts: false collections: - chocolatey.chocolatey tasks: # 后续任务代码保持不变
4. 确保执行环境镜像包含集合
如果使用自定义AWX-EE镜像,临时安装的集合会在容器重启后丢失。需在镜像构建配置文件execution-environment.yml中添加集合依赖,重新构建镜像:
dependencies: galaxy: collections: - name: chocolatey.chocolatey version: 1.3.0
内容的提问来源于stack exchange,提问作者Arek
相关产品推荐
相关产品推荐

