A pipeline whose correct output is usually no pull request

Pulling live firewall rules off every packet gateway and committing them to git, and the six days it took to make an SSH key readable.

Infra

What it does

The EPC inventory is one Ansible tree against five sites (three regions in the Americas, one in Europe, one in Asia-Pacific). The production file lists 49 entries under epc_tankers, 70 packet gateways, 19 across HSS, DRA, STP and SMSC, and seventy-odd GTP proxies in per-partner groups. None of it is generated from a cloud API; the inventory is handwritten, and it is the only thing that knows what exists.

The playbook here answers one narrow question: which firewall rules are loaded right now. It runs inside the container on each gateway, dumps both tables (iptables-save and ip6tables-save), and writes the result into a clone of the deployment repository:

- name: dump the iptables IPv4 rules
  community.docker.docker_container_exec:
    container: '{{ container }}'
    command: iptables-save
  register: iptables_data

Then it commits, pushes a branch, and leaves a diff for somebody to read (one directory per host, two files each). Running configuration becomes reviewable history. The gateway stays the source of truth; git only records what it was on Tuesday.

Getting the key out of Vault

This is where six days went. The role authenticates with an AppRole (role ID plus secret ID, on a dedicated mount) and reads a deploy key from the squad's KV2 engine:

- name: Get a Vault login data
  community.hashi_vault.vault_login:
    url: '{{ vault_addr }}'
    auth_method: '{{ vault_auth_method }}'
    role_id: '{{ vault_role_id }}'
    secret_id: '{{ vault_secret_id }}'
    mount_point: ansible_awx
  register: login_data

Four things were wrong before that worked — a path, a key name, a byte, and a package manager — and each cost about a day.

The KV2 path must omit data/, even though the HTTP API path contains it. The module inserts that segment itself, so a path copied out of the API explorer resolves to data/data/… and returns nothing useful. Two commits are titled with the conclusion that the module was unusable without a lookup (the same subject, twice) — which was wrong; the path was the problem.

Then the key names. The secret holds two entries (awx_id_rsa and awx_id_rsa.pub), and the second one has a dot in it. Dot notation cannot address a key containing a dot — ssh_access_keys.secret.awx_id_rsa.pub parses as four levels and finds nothing. Bracket subscript is the fix, and the commit says so plainly:

git_access_pvt_key: '{{ ssh_access_keys["secret"]["awx_id_rsa"] }}'
git_access_pub_key: '{{ ssh_access_keys["secret"]["awx_id_rsa.pub"] }}'

Then the newline. A private key written without a trailing newline is rejected by ssh as an invalid format, and the error blames the key, never the missing byte:

content: "{{ git_access_pvt_key }}\n"
dest: "/tmp/ssh_pvt_key"
mode: '0600'

One \n — and the commit before it asks to print the key material so the error could be read at all (a bad idea, on a local run, against a dev key). Not a proud moment, and the fastest way through.

Last, gh had to be installed on the runner to raise the pull request, which took its own run of commits through dnf modes (distro-sync, then check-update). That part did not survive: the role as it stands pushes a branch and stops.

The part that makes it usable

A pipeline that commits machine-generated output diffs on every run unless you remove whatever changes by itself. iptables-save emits two such things:

- name: Remove lines starting with \# from the rules file
  ansible.builtin.lineinfile:
    regexp: '^\s*#'
    state: absent

- name: Remove the count parameter from all the default rules
  ansible.builtin.replace:
    regexp: '^:([A-Z_ -]+) \[.*\]'
    replace: ':\1'

The comment lines carry a timestamp. The chain policy lines carry packet and byte counters in brackets (:INPUT ACCEPT [pkts:bytes]), which move every second the box is up. Strip both and an unchanged firewall produces an unchanged file.

The handler closes the loop by treating an empty commit as success:

failed_when: >
  (git_result.rc != 0) and
  ('nothing to commit, working tree clean' not in git_result.stdout)

That condition is the design, not a workaround. On most runs the right answer is no branch, no PR and a green job; a pipeline that cannot express "nothing changed" will train everyone to ignore it.

What it cost

Roughly 45 commits over six days in June 2024, nearly all of them one-line attempts at those same four problems. What remains is a role of about 120 lines that two playbooks share (the firewall dump, and an APN config dump). Its commit message records the job ID, the template, the launcher and the inventory used, so a diff with no human author still explains itself.

The same shape came back later for packet captures — tcpdump on every signalling interface (GTP-C on 2123, GTP-U on 2152, 2000 packets or 15 seconds), files pulled back, then aggregated. That one needed four fixes in a day, including a rewrite of the analysis from awk into Python (149 insertions, 151 deletions, in a file still named .sh) because the BSD awk on a laptop disagreed with the GNU one on the hosts. The pattern holds. Collecting the facts is the easy half; the only hard part is parsing what comes back.