2014-04-24 22 views
3

我怎樣才能重新使用所有我attributes部分,除了maven在測試廚房中使用類似的「套件」進行代碼重用?

 suites: 
     - name: DEV 

    attributes: 
      'ant': &ant 
      'version': '1.9.3' 
      'home': '/my/path/ant' 
      'maven': 
      'version': 3 
      'm2_home': '/my/path/maven' 
      '3': 
       'version': '3.2.1' 
       'maven_rc': 
      'opts': '' 

對於我TESTING例如,我想繼承以上所有的屬性,除了maven,我想這倍率(不同版本):

- name: TESTING 

    attributes: 
      <<: *ant  # re-use ant as it's the same configuration 
      'maven':  # different version for TESTING 
      'version': 3 
      'm2_home': '/my/path/maven' 
      '3': 
       'version': '3.0.5' 
       'maven_rc': 
      'opts': '' 
+1

你想讀此:http://stackoverflow.com/questions/8466223/reuse-a-block-of-code-in-yaml – sethvargo

+0

謝謝,塞思。我讀了那篇文章並更新了我的問題。你可以看一下嗎? –

+0

如何創建一個'base'或'default' run_list,你再從兩'dev'和'qa',與QA加在上面配方繼承?請注意,你將不得不繼承'run_list',而不是整個套件。 – JeanMertz

回答

0

值得關注的是,你可以在你的kitchen.yml使用厄爾布語法

<% my_attrs = {'foo' => 'bar'} %> suites: - name: one attributes: <%= my_attrs.to_yaml %> - name: two attributes: <%= my_attrs.merge('baz' => 'whatever').to_yaml %>

過度使用這種可迅速導致不可讀的configs,但要適量它可能是有用的。

2

你會想編輯您的.kitchen.yml的平臺,你想成爲通用的任何屬性下。如果您想要更改它們,那麼您只需將它們置於具有不同值的套件部分下。

platforms: 
    - name: ubuntu-12.04 
    driver_config: 
     box: ubuntu-12.04 
    run_list: 
     - recipe[apt::default] 
    attributes: 
     ant: &ant 
     version: '1.9.3' 
     home: '/my/path/ant' 
     maven: 
     version: 3 
     m2_home: '/my/path/maven' 
     3: 
      version: '3.2.1' 
      maven_rc: 
     opts: '' 

suites: 
    - name: default 
    run_list: 
     - recipe[cookbook::default] 
    attributes: 

    - name: testing 
    run_list: 
     - recipe[cookbook::default] 
    attributes: 
     maven: 
     3: 
      version: '3.0.5' 

然後,您可以通過調用node['maven']['version']檢索如果在套房部分覆蓋,這將改變取決於當前值訪問食譜裏面的屬性。

相關問題