태그 보관물: ansible

ansible

yml에 vars가 없을 때 강제로 오류가 발생합니까? 때 강제로 Ansible을 강제 실행할

정의되지 않은 yml 파일에서 var를 바꿀 때 강제로 Ansible을 강제 실행할 수 있습니까? 빈 문자열로 자동 대체되는 대신 오류가 발생합니까?



답변

네 가능합니다. 복잡한 변수 데이터 액세스 에서 온라인 설명서를 확인하십시오 .

다음을 정확히 수행하는 예제가 제공됩니다.

tasks:
    - shell: echo "I've got '{{ foo }}' and am not afraid to use it!"
      when: foo is defined

    - fail: msg="Bailing out: this play requires 'bar'"
      when: bar is not defined

답변

이 줄을 [defaults]ansible.cfg 섹션에 추가하십시오 :

error_on_undefined_vars = True

변수가 정의되지 않은 경우 오류 메시지가 표시됩니다.


답변

변수 정의

roles/<role_name>/defaults/main.yml

처럼:

SUPERVAR:
  VAR1:foo
  VAR2:bar

그런 다음에

roles/<role_name>/tasks/main.yml

처럼:

- fail: msg="{{ item }} is not defined"
  when: not {{ item }}
  with_items:
    - SUPERVAR.VAR1
    - SUPERVAR.VAR2

답변