2017-03-15 1 views
0

|d() (예 : reports 또는 forecast 등) 변수를 허용 할Ansible 2.0 업그레이드 - 기본 필터 체인 오류

"{{ oracle1.instance.reports|d().forecast|d().email|d('[email protected]') }}" 

는 말에 기본 변수에 디폴트 할 Ansible 2.0 이전에, 기본 필터가 허용되었다 프로그램에서 reports 또는 forecast에 대한 인스턴스를 찾을 수없는 경우이 경우 (기본 변수는 [email protected]입니다.) reports & forecasts은 일부 환경에서는 정의되었지만 전부는 아니므로 스크립트 행에서 이러한 변수를 제거 할 수 없습니다. Ansible 2.X에서 기본 필터 |d()이 필요하지 않으며 코드는 다음과 같이 쓸 수있다 :

fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'dict object' has no attribute 'reports'\n\nThe error appears to have been in '/home/ansible/svn/stable-1.6-ansible2_other/playbooks/buildEnvironment/temp2.yml': line 21, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n ignore_errors: false\n - debug:\n ^here\n"}

어떤 도움 :

"{{ oracle1.instance.reports.forecast.email|d('[email protected]') }}" 

위의 스크립트를 실행하는 경우,이 오류가 무엇입니까 이 문제 또는 2.X에 대한 기본 변수 필터를 사용하는 방법에 대한 많은 감사를드립니다!

+0

"* 이전에, 기본 필터가 허용되었다 Ansible 2.0 *"- 정말? 템플릿은 어떤 버전에서 성공적으로 해결됩니까? 나는 방금 1.9.5로 시도하고 template string 동안 template error가 발생했다 : 예상 토큰 'print statement'의 끝. ','got '.' – techraf

답변

0

나는 이런 식으로 작업을 수행합니다

"{{ ((((oracle1 | default({})).instance | default({})).reports | default({})).forecast | default({})).email | default('[email protected]') }}" 
+0

완벽하게 작동했다. 정말 고마워! –