mirror of
https://github.com/ansible/ansible.git
synced 2026-08-03 08:03:05 +02:00
Fix unexpected exception when a role has an empty argument_specs.yml (#75604)
* Fix role with empty argument_specs.yml * Use try/except and add changelog fragment * Always return a dict * Add test for empty argument_specs key
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
---
|
||||
bugfixes:
|
||||
- roles - fix unexpected ``AttributeError`` when an empty ``argument_specs.yml`` is present (https://github.com/ansible/ansible/pull/75604).
|
||||
@@ -294,7 +294,10 @@ class Role(Base, Conditional, Taggable, CollectionSearch):
|
||||
if self._loader.path_exists(full_path):
|
||||
# Note: _load_role_yaml() takes care of rebuilding the path.
|
||||
argument_specs = self._load_role_yaml('meta', main='argument_specs')
|
||||
return argument_specs.get('argument_specs', {})
|
||||
try:
|
||||
return argument_specs.get('argument_specs') or {}
|
||||
except AttributeError:
|
||||
return {}
|
||||
|
||||
# We did not find the meta/argument_specs.[yml|yaml] file, so use the spec
|
||||
# dict from the role meta data, if it exists. Ansible 2.11 and later will
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
---
|
||||
argument_specs:
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
- debug:
|
||||
msg: "Role with empty argument_specs key"
|
||||
@@ -0,0 +1 @@
|
||||
---
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
- debug:
|
||||
msg: "Role with empty argument_specs.yml"
|
||||
@@ -338,3 +338,19 @@
|
||||
- debug: var=ansible_failed_result
|
||||
- fail:
|
||||
msg: "Should not get here"
|
||||
|
||||
- name: "New play to reset vars: Test empty argument_specs.yml"
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Import role with an empty argument_specs.yml
|
||||
import_role:
|
||||
name: empty_file
|
||||
|
||||
- name: "New play to reset vars: Test empty argument_specs key"
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Import role with an empty argument_specs key
|
||||
import_role:
|
||||
name: empty_argspec
|
||||
|
||||
Reference in New Issue
Block a user