Ansible 2.0升级-默认过滤器链错误
Ansible 2.0 upgrade - default filter chain error
在 Ansible 2.0 之前,允许使用默认过滤器
"{{ oracle1.instance.reports|d().forecast|d().email|d('testing@gmail.com') }}"
其中 |d()
将允许变量(例如 reports
或 forecast
)默认为最后的默认变量(在这种情况下,默认变量是 testing@gmail.com
) 如果程序找不到 reports
或 forecast
的实例。 reports
& forecasts
在某些环境中定义,但并非在所有环境中定义,因此我无法从脚本行中删除这些变量。在 Ansible 2.X 中,默认过滤器 |d()
不是必需的,代码可以这样写:
"{{ oracle1.instance.reports.forecast.email|d('testing@gmail.com') }}"
当运行上面的脚本时,我得到这个错误:
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 将不胜感激!
我是这样做的:
"{{ ((((oracle1 | default({})).instance | default({})).reports | default({})).forecast | default({})).email | default('testing@gmail.com') }}"
在 Ansible 2.0 之前,允许使用默认过滤器
"{{ oracle1.instance.reports|d().forecast|d().email|d('testing@gmail.com') }}"
其中 |d()
将允许变量(例如 reports
或 forecast
)默认为最后的默认变量(在这种情况下,默认变量是 testing@gmail.com
) 如果程序找不到 reports
或 forecast
的实例。 reports
& forecasts
在某些环境中定义,但并非在所有环境中定义,因此我无法从脚本行中删除这些变量。在 Ansible 2.X 中,默认过滤器 |d()
不是必需的,代码可以这样写:
"{{ oracle1.instance.reports.forecast.email|d('testing@gmail.com') }}"
当运行上面的脚本时,我得到这个错误:
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 将不胜感激!
我是这样做的:
"{{ ((((oracle1 | default({})).instance | default({})).reports | default({})).forecast | default({})).email | default('testing@gmail.com') }}"