【问题标题】:Ansible-lint: do not understand confusing linting errorAnsible-lint:不理解混淆 linting 错误
【发布时间】:2021-02-12 18:02:03
【问题描述】:

我正在使用 CI/CD 管道,部分管道针对一些剧本运行 ansible-lint。 Ansible-lint 通过 docker 容器运行。我有一些剧本给了我一个非常令人困惑的错误。这是一个示例 playbook 以及运行 ansible-lint 的结果。

剧本:

---
- name: "SET CONFIG"
  hosts: my_host

  tasks:
    - name: Test
      debug:
        msg: "Test message"

ansible-lint 命令:ansible-lint playbook.yml

ansible-lint 输出:

Couldn't parse task at playbook.yml:6 (conflicting action statements: debug, __line__

The error appears to be in '<unicode string>': line 6, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

(could not open file to display line))
{ 'debug': {'__file__': 'playbook.yml', '__line__': 8, 'msg': 'Test message'},
  'name': 'Test',
  'skipped_rules': []}

我在几个剧本上都遇到了这个错误,但我将其归结为这个小测试剧本来说明正在发生的事情。我真的无法理解发生了什么。如果我删除 tasks 定义,剧本 lints 就好了。

我正在运行以下命令:

  • Python:3.8.5
  • Ansible:2.8.5
  • Ansible-lint:4.2.0
  • 码头工人:19.03.5

有人知道发生了什么吗?我在 StackOverflow 上看到过其他类似的问题,但这些解决方案似乎都表明需要分离任务。这个剧本只有一个任务。

【问题讨论】:

  • 您确定您不只是遇到回车问题吗?就像 Windows \r 一样,当文件安装在容器上时会被错误解释。就我而言,使用您的确切剧本,我无法复制。
  • 您遗漏了您的 ansible 版本,但 based on this bug 我猜是 2.10 :-) -- 还有,ansible-lint 4.3.5 is the latest
  • @β.εηοιτ.βε 我认为这可能是问题,但我在 Mac 上,命令运行得很好。当我在 Linux 机器上运行 docker 命令时,我得到了错误。另外,我已经手动重新创建了几次文件,以确保我没有任何坏字符。在我看来,这可能部分是this issue 的错
  • @Winsel 但这个问题是由 OP 剧本中的一个实际问题引起的:一个参数留空,所以它最终是 None,这对于使用的模块无效。您的剧本中似乎没有任何无效内容。
  • 你是对的。没注意到。现在我更加困惑了。我去看看能不能升级到4.3.5。

标签: python docker ansible


【解决方案1】:

我遇到了几乎相同的问题,但在基于 Debian Stretch 的 docker 映像中使用了 python2.7。 Ansible 2.10 是常见因素,@mdaniel 的建议是正确的,因为该错误是问题所在 - 因此升级到 ansible 4.3.5 或更高版本是解决方案。

【讨论】:

【解决方案2】:

这个解决方案在 Gitlab-CI 中适用于我:

lint_playbooks:
  stage: test:pre
  script:
    - PYTHONIOENCODING=utf-8 ansible-lint *.yml -vvvv

【讨论】:

    猜你喜欢
    • 2021-02-05
    • 1970-01-01
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    • 1970-01-01
    • 2013-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多