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