मेरे Ansible भूमिकाओं के लिए, कुछ भूमिकाओं प्राप्त विशिष्ट विन्यास सेटिंग्स से वैश्विक चर वैश्विक चर हो सकता है अपरिभाषित. निम्न कोड illustrates स्कीमा:
- hosts: localhost
vars:
bar: '{{ foo }}'
tasks:
# Assume foo comes from an Ansible environment
- debug: var=foo
# Assume bar comes from a role default
- debug: var=bar
# Catched by the "is defined" condition
- debug: msg="foo is defined"
when: 'foo is defined'
# Cannot catch undefined exception?!
- debug: msg="bar is defined"
when: 'bar is defined'
सब कुछ काम करता है के रूप में की उम्मीद है, लेकिन पिछले बयान: Ansible अपवाद उठाती है क्योंकि foo
अपरिभाषित है (हाँ, यह अपरिभाषित है).
PLAY [localhost] *********************************************************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************************************
ok: [localhost]
TASK [debug] *************************************************************************************************************************************************************
ok: [localhost] => {
"foo": "VARIABLE IS NOT DEFINED!"
}
TASK [debug] *************************************************************************************************************************************************************
ok: [localhost] => {
"bar": "VARIABLE IS NOT DEFINED!"
}
TASK [debug] *************************************************************************************************************************************************************
skipping: [localhost]
TASK [debug] *************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The conditional check 'bar is defined' failed. The error was: error while evaluating conditional (bar is defined): {{ foo }}: 'foo' is undefined\n\nThe error appears to be in '.../test-undef.yml': line 9, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n when: 'foo is defined'\n - debug: msg=\"bar is defined\"\n ^ here\n"}
तो क्यों करता है bar
नहीं "मूल्यांकन" करने के लिए undefined
की तरह foo
? और कैसे कर सकते हैं मैं इस जाल "बहु-स्तर" undefinedness?