From ea44066388366c4218fdfcfa5efbc65968ca1beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Mon, 3 Oct 2022 14:25:31 -0400 Subject: [PATCH] inventory/aws_ec2: drop := operator because we still support py3.6 (#1098) inventory/aws_ec2: drop := operator because we still support py3.6 Depends-On: ansible/ansible-zuul-jobs#1649 Depends-On: #1100 The operator was included with Python 3.8. See: https://docs.python.org/3/whatsnew/3.8.html#assignment-expressions Reviewed-by: Alina Buzachis --- changelogs/fragments/inventory-aws_ec2-avoid-py38-syntax.yaml | 3 +++ plugins/inventory/aws_ec2.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/inventory-aws_ec2-avoid-py38-syntax.yaml diff --git a/changelogs/fragments/inventory-aws_ec2-avoid-py38-syntax.yaml b/changelogs/fragments/inventory-aws_ec2-avoid-py38-syntax.yaml new file mode 100644 index 00000000000..ac3b5869242 --- /dev/null +++ b/changelogs/fragments/inventory-aws_ec2-avoid-py38-syntax.yaml @@ -0,0 +1,3 @@ +--- +trivial: + - "inventory/aws_ec2 - Avoid the := operator (py3.8+) because we still support Python 3.6." diff --git a/plugins/inventory/aws_ec2.py b/plugins/inventory/aws_ec2.py index c532f2b065b..8b2604ed824 100644 --- a/plugins/inventory/aws_ec2.py +++ b/plugins/inventory/aws_ec2.py @@ -774,9 +774,9 @@ def iter_entry(self, hosts, hostnames, allow_duplicated_hosts=False, hostvars_pr for host in hosts: if allow_duplicated_hosts: hostname_list = self.get_all_hostnames(host, hostnames) - elif preferred_hostname := self._get_preferred_hostname(host, hostnames): - hostname_list = [preferred_hostname] else: + hostname_list = [self._get_preferred_hostname(host, hostnames)] + if not hostname_list or hostname_list[0] is None: continue host_vars = self.prepare_host_vars(