35 lines
826 B
Bash
Executable file
35 lines
826 B
Bash
Executable file
#!/bin/sh
|
|
|
|
if [ $# != 2 ]; then
|
|
echo "ERR: Must have two arguments: DNS server name and zone/environment" 1>&2
|
|
return 2
|
|
fi
|
|
|
|
ZONE=$2
|
|
SERVER=$1
|
|
FACTS_DIR="/var/lib/puppet/yaml/facts"
|
|
ZONE_FILE="/srv/puppet/files/common/dns/db.$ZONE-dynamic.$SERVER"
|
|
|
|
if [ ! -d "${FACTS_DIR}" ]; then
|
|
echo "ERR: Cannot find Facter facts directory ${FACTS_DIR}" 1>&2
|
|
exit 3
|
|
fi
|
|
|
|
if [ -f "${ZONE_FILE}" ]; then
|
|
rm $ZONE_FILE
|
|
fi
|
|
cd $FACTS_DIR
|
|
for i in `grep -l "environment: $ZONE" *`;
|
|
do
|
|
echo $i
|
|
hn=`grep hostname $i | cut -f 2 -d ':' | tr -d ' '`
|
|
ip=`grep "ipaddress:" $i | cut -f 2 -d ':'`
|
|
a=`grep "aliases:" $i | cut -f 2 -d ':' | tr -d '"' | tr -d ' '| tr ',' "\n"`;
|
|
echo "$hn IN A $ip" >> $ZONE_FILE
|
|
if [ "$a" != "" ]; then
|
|
for j in $a;
|
|
do
|
|
echo "$j CNAME $hn" >> $ZONE_FILE
|
|
done
|
|
fi
|
|
done
|