From f659cc596352d047adf21cf5890d41c747a9be61 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Tue, 30 Jan 2018 12:56:16 -0600 Subject: [PATCH] Guard against assignments that are not ast.Name in docs parsing (#35513) --- lib/ansible/parsing/metadata.py | 2 +- test/sanity/validate-modules/main.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ansible/parsing/metadata.py b/lib/ansible/parsing/metadata.py index c021cc2c2e1..70ed4491ce9 100644 --- a/lib/ansible/parsing/metadata.py +++ b/lib/ansible/parsing/metadata.py @@ -191,7 +191,7 @@ def extract_metadata(module_ast=None, module_data=None, offsets=False): for root_idx, child in reversed(list(enumerate(module_ast.body))): if isinstance(child, ast.Assign): for target in child.targets: - if target.id == 'ANSIBLE_METADATA': + if isinstance(target, ast.Name) and target.id == 'ANSIBLE_METADATA': metadata = ast.literal_eval(child.value) if not offsets: continue diff --git a/test/sanity/validate-modules/main.py b/test/sanity/validate-modules/main.py index 71a881a67c5..92c1ad2f496 100755 --- a/test/sanity/validate-modules/main.py +++ b/test/sanity/validate-modules/main.py @@ -753,6 +753,9 @@ class ModuleValidator(Validator): for child in self.ast.body: if isinstance(child, ast.Assign): for grandchild in child.targets: + if not isinstance(grandchild, ast.Name): + continue + if grandchild.id == 'DOCUMENTATION': docs['DOCUMENTATION']['value'] = child.value.s docs['DOCUMENTATION']['lineno'] = child.lineno