From 0ecb2abf433e883b73cc45d283eabf7d665ec736 Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Thu, 6 Aug 2020 12:18:07 -0400 Subject: [PATCH] [stable-2.9] linux facts - return proper broadcast address (#64528) (#71065) * linux facts - return proper broadcast address Check that the value being returned is actually a broadcast address * Add tests * Cleanup tests (cherry picked from commit e6bf202738) Co-authored-by: Sam Doran --- .../linux-network-facts-broadcast-address.yaml | 2 ++ .../module_utils/facts/network/linux.py | 3 ++- .../targets/facts_linux_network/aliases | 4 ++++ .../targets/facts_linux_network/meta/main.yml | 2 ++ .../targets/facts_linux_network/tasks/main.yml | 18 ++++++++++++++++++ 5 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/linux-network-facts-broadcast-address.yaml create mode 100644 test/integration/targets/facts_linux_network/aliases create mode 100644 test/integration/targets/facts_linux_network/meta/main.yml create mode 100644 test/integration/targets/facts_linux_network/tasks/main.yml diff --git a/changelogs/fragments/linux-network-facts-broadcast-address.yaml b/changelogs/fragments/linux-network-facts-broadcast-address.yaml new file mode 100644 index 00000000000..c6e627aee8f --- /dev/null +++ b/changelogs/fragments/linux-network-facts-broadcast-address.yaml @@ -0,0 +1,2 @@ +bugfixes: + - linux network facts - get the correct value for broadcast address (https://github.com/ansible/ansible/issues/64384) diff --git a/lib/ansible/module_utils/facts/network/linux.py b/lib/ansible/module_utils/facts/network/linux.py index 0494a1abf70..93965f2d0c0 100644 --- a/lib/ansible/module_utils/facts/network/linux.py +++ b/lib/ansible/module_utils/facts/network/linux.py @@ -173,7 +173,8 @@ class LinuxNetwork(Network): if '/' in words[1]: address, netmask_length = words[1].split('/') if len(words) > 3: - broadcast = words[3] + if words[2] == 'brd': + broadcast = words[3] else: # pointopoint interfaces do not have a prefix address = words[1] diff --git a/test/integration/targets/facts_linux_network/aliases b/test/integration/targets/facts_linux_network/aliases new file mode 100644 index 00000000000..6f1c2c05374 --- /dev/null +++ b/test/integration/targets/facts_linux_network/aliases @@ -0,0 +1,4 @@ +needs/privileged +shippable/posix/group2 +skip/freebsd +skip/osx diff --git a/test/integration/targets/facts_linux_network/meta/main.yml b/test/integration/targets/facts_linux_network/meta/main.yml new file mode 100644 index 00000000000..07faa217762 --- /dev/null +++ b/test/integration/targets/facts_linux_network/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_tests diff --git a/test/integration/targets/facts_linux_network/tasks/main.yml b/test/integration/targets/facts_linux_network/tasks/main.yml new file mode 100644 index 00000000000..af4dde96aa2 --- /dev/null +++ b/test/integration/targets/facts_linux_network/tasks/main.yml @@ -0,0 +1,18 @@ +- block: + - name: Add IP to interface + command: ip address add 100.42.42.1/32 dev {{ ansible_facts.default_ipv4.interface }} + ignore_errors: yes + + - name: Gather network facts + setup: + gather_subset: network + + - name: Ensure broadcast is reported as empty + assert: + that: + - ansible_facts[ansible_facts['default_ipv4']['interface']]['ipv4_secondaries'][0]['broadcast'] == '' + + always: + - name: Remove IP from interface + command: ip address delete 100.42.42.1/32 dev {{ ansible_facts.default_ipv4.interface }} + ignore_errors: yes