Generate the Hosts Dynamically on OpenStack servers
$ go get github.com/udzura/monkfish/cmd/monkfish
# Or on project root
$ make install
$ monkfish -help
Usage of monkfish:
-V Verbose mode
-c string
Config path (default "/etc/monkfish.ini")
-random-delay int
Random delay before to access OpenStack API, in second
-t string
Target file to write hosts (default "/etc/hosts")
-version
Just show version and quit
-w Write to file
First, set the /etc/hosts.base
e.g. running sudo cp -a /etc/hosts /etc/hosts.base
Then, create a config file /etc/monkfish.ini
like:
[default]
os_username = "udzura"
os_password = "t0nkotsu-r@men"
os_tenant_name = "the_tenant"
os_auth_url = "https://your.keystone.host:9999/v2.0"
os_region = "RegionOne"
domain = "monk.example.tld"
internal_domain = "monk.local"
lan_ip_prefix = "10.10.100." # Optional
use_only_hostname = true # Optional, when you want instances named like `foo001.example.tld` to be `foo001.your.lan`
Then set crontab:
@reboot root /usr/local/bin/monkfish -w
*/3 * * * * root /usr/local/bin/moknfish -w
[Pro tips] When you want to avoid thundering herd:
*/3 * * * * /usr/local/bin/moknfish -random-delay 60'
After this the /etc/hosts
will be periodicaly updated from /etc/hosts.base
and existing server networks.
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
54.248.999.999 proxy001.monk.example.tld
10.187.100.10 proxy001.monk.local
176.34.999.999 worker003.monk.example.tld
10.187.100.11 worker003.monk.local
175.41.999.999 worker004.monk.example.tld
10.187.100.12 worker004.monk.local
...
- Do not pass
-w
if you don't want to update hosts. Without-w
, entries are outputted to stdout. - Pass
-V
for debug.
/usr/local/bin/monkfish -V
name: proxy001
54.248.999.999 proxy001.monk.example.tld
10.187.100.10 proxy001.monk.local
name: worker003
176.34.999.999 worker003.monk.example.tld
10.187.100.11 worker003.monk.local
...
Original idea is from the implementation of @lamanotrama's Perl script.
MIT.
- Automated update via
consul watch