2017-08-01 13 views
0

我有一個requirements.yml文件,該文件列出了相關爲Ansible角色:ansible星系失敗與空元/依賴性main.yml

--- 

- src: [email protected]:group/dependency1.git 
    scm: git 
    name: name1 

- src: [email protected]:group/dependency1.git 
    scm: git 
    name: name2 

這些角色沒有任何依賴自己,因爲他們在私人SCM系統上(除其他原因外),他們不需要任何元數據。但是,在Ansible依賴中加載需要該文件存在。因此,依賴關係有一個空的meta/main.yml來啓用使用可靠星系。

使用時安裝的依賴:

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正確處理我的依賴關係?

回答

0

事實證明,空白的meta/main.yml不足以將角色處理爲依賴項。我的假設是角色對象被初始化,沒有元數據字段,如果該文件是空的,因爲the line mentioned in the verbose output是:

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

「角色」是在此之前的線路上使用,因此將是一個例子,而這是首先提到「元數據」。

這部分代碼是處理嵌套安裝的依賴關係,如線之上正在檢查,以確定它是否應該處理嵌套的依賴關係。

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: 

就足夠了這個目的。

2

我只是fixed thisdevel。應該使Ansible的2.4版本發佈。