【问题标题】:ansible-galaxy fails on dependency with empty meta/main.ymlansible-galaxy 依赖空 meta/main.yml 失败
【发布时间】:2018-01-08 00:51:17
【问题描述】:

我有一个 requirements.yml 文件,其中列出了 Ansible 角色的依赖项:

---

- src: git@gitrepo:group/dependency1.git
  scm: git
  name: name1

- src: git@gitrepo:group/dependency1.git
  scm: git
  name: name2

这些角色本身没有任何依赖关系,并且由于它们位于私有 SCM 系统上(以及其他原因),它们不需要任何元数据。但是,加载 Ansible 依赖项需要此文件存在。因此,依赖项有一个空白的 meta/main.yml 以启用 ansible-galaxy。

安装依赖项时使用:

ansible-galaxy install --role-file requirements.yml --roles-path foo

安装第一个依赖项后,会报错:

ERROR! Unexpected Exception: 'NoneType' object has no attribute 'get'

使用非常详细的输出,可以找到错误:

galaxy.py", line 394

经过实验,多次运行该命令将通过依赖关系,一次一个。因此,嵌套依赖项会失败;因为父级会安装然后出错,或者 ansible-galaxy 会认为父级已经安装并跳过依赖项。

问题是:如何阻止此错误的发生并让 ansible-galaxy 正确处理我的依赖项?

【问题讨论】:

    标签: ansible ansible-2.x ansible-galaxy


    【解决方案1】:

    我只是在fixed thisdevel。应该是 Ansible 的 2.4 版本。

    【讨论】:

      【解决方案2】:

      事实证明,空白的 meta/main.yml 不足以将角色作为依赖项处理。我的假设是,如果文件为空白,则角色对象在没有元数据字段的情况下被初始化,因为the line mentioned in the verbose output 是:

      role_dependencies = role.metadata.get('dependencies') or []
      

      “role”在此行之前使用,因此将是一个实例,而这是第一次提到“元数据”。

      这部分代码正在处理嵌套依赖项的安装,因为上面的行正在检查以确定它是否应该处理嵌套依赖项。

      if not no_deps and installed:
        role_dependencies = role.metadata.get('dependencies') or []
        ...
      

      如果这一行也检查了元数据是否存在,例如:

      if not no_deps and installed and metadata:
      

      那么这部分将被(正确地)跳过。然而,由于 Ansible 没有做这个检查,元数据是 'NoneType' 对象,它确实没有属性 'get'。

      这意味着 meta/main.yml 文件中至少需要一个键才能作为依赖项进行处理。有一个 meta/main.yml 文件:

      ---
      
      galaxy_info:
      

      足以达到此目的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-27
        • 2014-07-01
        • 2017-09-16
        相关资源
        最近更新 更多