lgaggini / bind2ansible

bind2ansible is a tool to generate ansible static inventory from bind9 zones files.

Home Page:https://lgaggini.github.io/bind2ansible/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bind2ansible

bind2ansible is a tool to generate ansible static inventory from bind9 zones files. It's intended to be runned on a post-merge hook (example included) on the repo which hosts the bind zones files but it could be runned also manually.

Constraints

  • bind zones files are all in the same directory and they are named: db.{{ 2ndlevelel }}.{{ tld }}
  • clusters hosts are named: {{ cluster }}{{ index }}.{{ 2ndlevelel }}.{{ tld }}
  • index identifies if the host is an integration host (>90), a staging host (<90, >80) or production hosts (<90)

Installation

git clone https://github.com/lgaggini/bind2ansible.git

Configuration

At the top of bash scripts and in the bind.ini there are configuration settings:

bind2ansible.sh

# default ansible user
default_user="root"
# default custom ssh port
custom_port=""
# bind zones path
zones_path="/bind/files/zones/"
# zones filename to parse
zones=(db.my.zone1 db.my.zone2)
# start to parse after this line
parse_after="SERVER LINUX"
# line (records) to include
include_filter=" A "
# lines (vip, windows cluster, etc..) to exclude
exclude_filter="^;"

post-merge

# regexp to match zone files on the git repo to monitor for changes
bind_zone_regexp="/bind/files/zones/"
# where to write the ansible static inventory
ansible_inventory="/etc/ansible/hosts"
# command to run on monitored files changes, the awk part removes
# duplicate domains based on the last level, the first zone defined
# in bind2ansible has the precedence
bind2ansible(){
    /usr/local/bin/bind2ansible.sh | awk -F"." '!a[($1)]++' > $ansible_inventory
}

bind.ini

[bind]

zones_path = /bind/files/zones/
zones = db.my.zone1,db.my.zone2
include_filter = "\sA\s"
exclude_filter = "^;|vip"
loglevel = "INFO"
start = "PARSE AFTER HERE"

Run

Manual Run

cd bind2ansible
./bind2ansible.sh

Post Merge Hook Run

Copy the post-merge script on your repo in the .git/hook folder and if the settings are ok on first git pull including files matching the bind_zone_regexp the script will be launched.

Dynamic inventory Run

Now also a dynamic inventory version is present, you can use it:

cd bind2ansible
ansible -i bind.py {{ group or host }} -m ping

About

bind2ansible is a tool to generate ansible static inventory from bind9 zones files.

https://lgaggini.github.io/bind2ansible/

License:GNU General Public License v3.0


Languages

Language:Python 68.0%Language:Shell 32.0%