2014-04-22 1 views
0

심지어 가능 할지도 모른다.꼭두각시에서 해시 값으로 키를 얻는 방법

$some_external_value = 'pew_pew' 
$dict = { 
    ensure => $ensure, 
    configuration => { 
     "random_name-${some_external_value}" => { 
      command => 'python script.py config/random_name-${some_external_value}.cfg', 
     }, 
     "some_other_name-${some_external_value}" => { 
      command => 'python script.py config/some_other_name-${some_external_value}.cfg', 
     }, 
     "without-external" => { 
      command => "python script.py config/without-external.cfg", 
      user => 'cluster', 
     }, 
     } 
} 
notice ($dict["configuration"]["some_other_name-${some_external_value}"]["command"]) 

내가

notice: Scope(Class[main]): python script.py config/some_other_name-pew_pew.cfg 

한 번만하고 그냥 참조 후 키 이름을 쓸 수있는 몇 가지 트릭이 거기를 얻을 : 는이 같은 매니페스트가 있나요?

"some_other_name-${some_external_value}" => { 
    command => 'python script.py config/${wild_magic_variable_pasting_key_here}.cfg', 
}, 

답변

0

custom parser function으로 연결할 수 있습니다. 루비 함수 재귀 해당 키 값과 __KEY__ 토큰을 교체하는 작업을 수행

$orig_dict = { 
    ... 
    configuration => { 
    "random_name-${some_external_value}" => { 
     command => 'python script.py config/__KEY__.cfg', 
    }, 
    ... 
} 

$dict = keysubst($orig_dict) 

....

관련 문제