到Ansible 2.0之前,默認過濾器被允許Ansible 2.0升級 - 默認過濾器鏈誤差
"{{ oracle1.instance.reports|d().forecast|d().email|d('[email protected]') }}"
其中|d()
將允許變量(如reports
或forecast
),以在端部被默認爲默認變量(在這種情況下,默認變量是[email protected]
)如果程序找不到reports
或forecast
的實例。 reports
& forecasts
在某些環境中定義,但不是全部,因此我無法從腳本行中刪除這些變量。在Ansible 2.X,默認過濾器|d()
是沒有必要的,代碼可以這樣寫:
"{{ oracle1.instance.reports.forecast.email|d('[email protected]') }}"
當運行上面的腳本,我收到此錯誤:
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"}
任何幫助關於這個問題或者如何使用Ansible 2.X的默認變量過濾器將非常感謝!
「*此前Ansible 2.0,默認篩選器允許*」 - 真的嗎?您的模板能夠成功解析哪個版本?我剛剛嘗試了1.9.5,並且出現了'模板錯誤,但模板字符串:期望的令牌'打印語句結束',得到'。''失敗。' – techraf