rss.png profile for ebal on Stack Exchange, a network of free, community-driven Q&A sites
ansible register

So here is a nice ansible trick to trigger a notify if only the exit status of a command is zero (without any errors)

  - name: Check named
    shell: /sbin/named-checkconf
    register: named_checkconf
    changed_when: "named_checkconf.rc == 0"
    notify: rndc reconfig

the named_checkconf contains the below values:

"changed": true,
"cmd": ["/sbin/rndc", "reconfig"],
"delta": "0:00:02.438532",
"end": "2015-04-07 15:02:21.349859",
"item": "",
"rc": 0,
"start": "2015-04-07 15:02:18.911327",
"stderr": "",
"stdout": ""
Tag(s): ansible, bind
bind: dump named db and split it into zone files

bind has a nice command to dump all the records (cache, views and zones) of a bind dns server to a single file.

> rndc --help

  dumpdb [-all|-cache|-zones] [view ...]
                Dump cache(s) to the dump file (named_dump.db).

Our named_dump.db file has 3.5m lines.

I was looking for a simple way to parse this entire formatted file and split the content of the zones to bind formatted zone files (for another project). So i was looking to implement the exactly opposite from: rndc dump --zones

i came with this:

grep 'IN' named_dump.db | awk -F[\'\/] '/Zone dump of/ {out=$2;}{print > out;}'

PS: The reason i am doing that, is that we dont have the 41435 zones to strict formatted bind zone files.
Some of them have “A” against “IN A”, some of them dont have TTL on RR (so the master TTL is in place), some of them use ‘@’ for origin etc etc etc. This is acceptable from bind, not really hard to parse when you are programming a custom provisioning mechanism.

Tag(s): bind, awk