내 Ansible 역할,일부 역할을 파생하는 특정 구성에서 설정을 전역변수 글로벌 변수가 될 수도 정의되지 않습니다. 다음 코드를 보여 줍니다 schema:
- 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?