python - ansible-lint 失败并显示 : AttributeError: 'str' object has no attribute 'resolve'

标签 python python-3.x ansible ansible-lint

在我设置的新 CentOS VM 上运行 github linter 工作流程时,出现以下错误:

Run ansible-lint --parseable ./ansible
Traceback (most recent call last):
  File "/usr/local/bin/ansible-lint", line 8, in <module>
    sys.exit(_run_cli_entrypoint())
  File "/usr/local/lib/python3.9/site-packages/ansiblelint/__main__.py", line 344, in _run_cli_entrypoint
    sys.exit(main(sys.argv))
  File "/usr/local/lib/python3.9/site-packages/ansiblelint/__main__.py", line 197, in main
    initialize_options(argv[1:])
  File "/usr/local/lib/python3.9/site-packages/ansiblelint/__main__.py", line 110, in initialize_options
    options.cache_dir = get_cache_dir(options.project_dir)
  File "/usr/local/lib/python3.9/site-packages/ansible_compat/prerun.py", line 13, in get_cache_dir
    basename = project_dir.resolve().name.encode(encoding="utf-8")
AttributeError: 'str' object has no attribute 'resolve'
Error: Process completed with exit code 1.

我尝试了以下软件包版本,但均因上述错误而失败:

  • python3:3.9.16
  • ansible:8.0.0 或 6.6.0
  • ansible-compat:4.1.2 或 2.2.7
  • ansible-core:2.15.0 或 2.13.9
  • ansible-lint:6.17.0 或 6.10.2

使用 pip,还安装了以下依赖项:

  • 薄片8
  • yamlint==1.28.0
  • 密码拼写
  • comment_parser

是否存在一些 linter 依赖项或我缺少的其他内容?

linter 作业中的步骤是:

 - name: 'Lint yaml - ansible, GH actions and GH workflows'
   run: yamllint -f parsable ./
   if: always()

最佳答案

在我的环境中,使用 pip install 将 ansible_compat 降级到 v3.0.1 解决了问题。从 v4 开始,prerun.py 包含给出错误的行。

关于python - ansible-lint 失败并显示 : AttributeError: 'str' object has no attribute 'resolve' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76465558/

相关文章:

python re,查找包含可选组的表达式

python - 在 Python 3 中删除部分字符串

python-3.x - 是否可以在 tkinter 中更改按钮颜色?

cron - 在 Ansible 中管理整个 crontab 文件

ansible - 在哪里可以找到可以改变输出的替代 Ansible callback_plugins 列表?

python - 使用 matplotlib 的 pandas 创建 seaborn 绘图

python - 为什么我的一个变量不需要声明而另一个变量需要声明?

python - python多处理的生产者/消费者问题

python - Pathlib Path.rename() 创建中间目录的方式?

linux - 在 ansible 剧本中添加 sudo_user 会使命令永远执行