Skip to content

Instantly share code, notes, and snippets.

@tiqwab
Last active February 23, 2021 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiqwab/0a1ffd9775ac8b712590f2fdd4e74dbf to your computer and use it in GitHub Desktop.
Save tiqwab/0a1ffd9775ac8b712590f2fdd4e74dbf to your computer and use it in GitHub Desktop.
Ansible の no_log に未定義の変数を使用したとき
$ ansible --version
ansible 2.10.5
  ...
  python version = 3.9.1 (default, Dec 13 2020, 11:55:53) [GCC 10.2.0]

用意した Playbook。

---

- hosts: localhost
  tasks:
    - name: Test
      debug:
        msg: 'hello'
      no_log: "{{ foo }}"
      # become: "{{ foo }}"

未定義の変数を no_log に使用したときのエラーが少し分かり辛い。 意図してやっている可能性がある?

$ ansible-playbook no-log-error.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [localhost] ********************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************
ok: [localhost]

TASK [Test] *************************************************************************************************************************
fatal: [localhost]: FAILED! => {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result"}

PLAY RECAP **************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

一方で例えば become に未定義の変数を使用した場合は、

$ ansible-playbook no-log-error.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [localhost] ********************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************
ok: [localhost]

TASK [Test] *************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The field 'become' has an invalid value, which includes an undefined variable. The error was: 'foo' is undefined"}

PLAY RECAP **************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment