てくなべ (tekunabe)

ansible / network automation / 学習メモ

[Ansible] The invalid attribute in Playbook causes error by default in Ansible 2.7

(日本語版はこちら)

Sample playbook

- hosts: localhost
  gather_facts: no

  tasks:
    - name: invalid attribute test
      debug:
        msg: test
      xxxxx: yyyy   # invalid attribute 

In Ansible version >= 2.6: WARNING

$ ansible-playbook -i localhost, attr.yml
 [WARNING]: Ignoring invalid attribute: xxxxxxxxxx


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

TASK [invalid attribute test] **********************************************
ok: [localhost] => {
    "msg": "test"
}

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

Processing of the playbook continues.

In Ansible version <= 2.7: ERROR

$ ansible-playbook -i localhost, attr.yml
ERROR! 'xxxxxxxxxx' is not a valid attribute for a Task

The error appears to have been in '/vagrant/a27/attr.yml': line 5, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  tasks:
    - name: invalid attribute test
      ^ here

This error can be suppressed as a warning using the "invalid_task_attribute_failed" configuration

Playbook processing is not executed.

You can change this behavior with the setting item INVALID_TASK_ATTRIBUTE_FAILED which determines the handling of invalid task attributes added in Ansible 2.7.

  • True: A task will result in errors (default)
  • False: A task will result in warnings

If you would like to change to False, set follows.

  • in ansible.cfg
[defaults]
invalid_task_attribute_failed=False

or

  • in environment variable
export ANSIBLE_INVALID_TASK_ATTRIBUTE_FAILED=False