You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行molecule test命令失败,单独命令正常运行求排查方案

问题排查与解决方法

看起来你遇到的问题是**molecule test命令触发了默认的lint检查环节,而单独执行create/converge子命令不会自动运行lint**,导致原本被忽略的Role元数据规则问题暴露出来了。

错误原因分析

从你提供的debug输出可以看到,错误来自ansible-lint的规则校验:

  • 规则[701]:要求Role的meta/main.yml必须包含platforms字段,这是Ansible Galaxy角色的必填元数据项
  • 规则[703]:要求替换掉galaxy_info里的默认占位符(比如your name、your description这些),不能直接使用模板内容

而molecule create/converge这类子命令默认不会触发完整的lint校验,所以这些问题没有被触发,直到运行molecule test(它会依次执行lint、create、converge、verify、destroy等全流程)才会报错。

具体解决步骤

1. 修复meta/main.yml文件

打开/root/.config/pip/molecule-testing/meta/main.yml,修改galaxy_info部分:

  • 添加platforms字段,指定你的Role支持的操作系统(比如Ubuntu、CentOS等)
  • 替换所有默认占位符为实际内容

示例修改后的内容:

galaxy_info:
  author: Your Actual Name
  description: A brief description of what this role does
  company: Your Company Name (or remove this line if not applicable)
  license: GPLv2
  min_ansible_version: 1.2
  # 添加platforms字段,根据你的需求调整
  platforms:
    - name: Ubuntu
      versions:
        - jammy
        - focal
    - name: CentOS
      versions:
        - 7
        - 8
  galaxy_tags:
    - pip
    - python
dependencies: []

2. 单独验证lint是否通过

修改完成后,先运行lint命令确认问题已修复:

molecule lint

或者直接用ansible-lint校验:

ansible-lint /root/.config/pip/molecule-testing/meta/main.yml

3. 重新运行molecule test

当lint校验通过后,再执行molecule test应该就能正常完成全流程了。

额外说明

如果你确实不需要严格遵循Ansible Galaxy的元数据规则,也可以通过修改molecule.yml配置来跳过lint环节,但不推荐这么做(因为lint能帮你提前发现潜在问题)。如果要跳过,可以在molecule.yml中添加:

lint:
  enabled: false

内容的提问来源于stack exchange,提问作者change198

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:03:03