27 lines
538 B
Bash
Executable File
27 lines
538 B
Bash
Executable File
#!/bin/sh
|
|
|
|
. ./config.sh
|
|
|
|
do_curl() {
|
|
curl -s -k -H "Authorization: Token ${TOKEN}" -X GET $1
|
|
}
|
|
|
|
echo "# generated by $0 at $(date)"
|
|
echo
|
|
cat dhcpd.conf.head
|
|
|
|
do_curl "https://${NETBOX}/api/ipam/ip-addresses/" | \
|
|
jq -r '.results[] | .assigned_object.device.name + .assigned_object.virtual_machine.name + " " + (.address / "/")[0] + " " + .assigned_object.url' |
|
|
while read name ip owner
|
|
do
|
|
mac=$(do_curl $owner | jq -r '.mac_address')
|
|
cat<<EOF
|
|
host $name {
|
|
fixed-address ${ip};
|
|
hardware ethernet ${mac};
|
|
}
|
|
EOF
|
|
done
|
|
|
|
echo "}"
|