From 78da8341a533a46f11cb73e67a2286457ae1f326 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 10 Oct 2018 12:34:58 -0400 Subject: [PATCH] manage levels for 'multiple included lists' (#46359) * manage levels for 'multiple included lists' fixes #46343 (cherry picked from commit 80d977bac65768bdd5cd675b9d1794640749431a) (cherry picked from commit ef6637895301842ff0a62f35ef1a6e517af60e39) --- changelogs/fragments/fix_flatten.yml | 2 ++ lib/ansible/plugins/filter/core.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/fix_flatten.yml diff --git a/changelogs/fragments/fix_flatten.yml b/changelogs/fragments/fix_flatten.yml new file mode 100644 index 0000000000..387033d7e1 --- /dev/null +++ b/changelogs/fragments/fix_flatten.yml @@ -0,0 +1,2 @@ +bugfixes: + - fix flatten to properly handle multiple lists in lists https://github.com/ansible/ansible/issues/46343 diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py index f6f6e28cde..21cf656a36 100644 --- a/lib/ansible/plugins/filter/core.py +++ b/lib/ansible/plugins/filter/core.py @@ -463,8 +463,8 @@ def flatten(mylist, levels=None): if levels is None: ret.extend(flatten(element)) elif levels >= 1: - levels = int(levels) - 1 - ret.extend(flatten(element, levels=levels)) + # decrement as we go down the stack + ret.extend(flatten(element, levels=(int(levels) - 1))) else: ret.append(element) else: