Each of our depots has a small Debian gateway that the handheld scanners talk to. Our playbook templates the scanner API's configuration, and one line in it has been the same for four years: bind_address: {{ ansible_default_ipv4.address }}. Every gateway had one network card on the depot LAN, so the default IPv4 address and the LAN address were the same thing.
In November we opened two new depots with a new gateway build. These have two network cards. enp1s0 is on the depot LAN. enp2s0 is a dedicated internet line for carrier traffic, and the default route goes out through it, because that is where everything outside the depot needs to go. The playbook ran green on both, our post deploy smoke test passed, and on the first morning not one scanner could connect.
ansible_default_ipv4 is not the main address of the machine, whatever the name suggests. Ansible fills it in by asking the kernel which route it would take to reach a public address, 8.8.8.8, and reporting the interface and address of that route. On the new gateways that was enp2s0, so the scanner API listened on the address of the internet line. The host firewall drops anything arriving on that interface except replies, so the service was unreachable from the outside, and it was unreachable from the LAN as well, because nothing was listening on the LAN address.
The smoke test ran on the gateway itself and called the API on the configured address. From inside the machine, the internet line's address is as local as any other, so the test connected every time.
The depots scanned on paper for two hours while we edited the file by hand on both gateways.
The template no longer reads a fact chosen by routing. Each gateway in the inventory declares its LAN interface, the template takes that interface's address from the facts, and an assert task fails the play if the address is not inside the depot LAN range that the inventory also holds. The smoke test now runs from the playbook's control node through the depot's LAN address, the way a scanner would reach it, and a gateway with two cards gets the same test as one with a single card.
A fact is answered by the question Ansible asked to get it. Ours was where traffic leaves the machine, and we had been reading it as where traffic arrives.
– Sergey Shinder



