summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xhetznertool43
-rw-r--r--ickdev.yaml2
2 files changed, 37 insertions, 8 deletions
diff --git a/hetznertool b/hetznertool
index 18a86fa..ed1fe5c 100755
--- a/hetznertool
+++ b/hetznertool
@@ -124,7 +124,7 @@ def create_func(config, args):
domain = get_domain_for_context(config, context)
style = get_style_for_context(config, context)
update_zone_file(style, domain, kick, args, zonedir, zonefile)
- write_inventory_files(config, args)
+ write_inventory_files(config, context)
def list_func(config, args):
@@ -172,6 +172,12 @@ def get_style_for_context(config, context):
return cc.get('style')
+def get_inventory_style_for_context(config, context):
+ print('context:', repr(context))
+ cc = get_config_for_context(config, context)
+ return cc.get('inventory-style')
+
+
def delete_func(config, args):
context = args['context']
use_context(context)
@@ -190,7 +196,7 @@ def delete_func(config, args):
kick = get_kick_for_context(config, context)
style = get_style_for_context(config, context)
update_zone_file(style, domain, kick, args, zonedir, zonefile)
- write_inventory_files(config, args)
+ write_inventory_files(config, context)
def update_zone_file(style, domain, kick, args, dirname, basename):
@@ -201,22 +207,21 @@ def update_zone_file(style, domain, kick, args, dirname, basename):
subprocess.check_call(['git', 'pull'], cwd=dirname)
+ filenames = [basename]
+
if style == 'qvarnlabs':
serial = int(open(serial_name).readline().strip())
serial += 1
open(serial_name, 'w').write('{}\n'.format(serial))
with open(filename, 'w') as f:
write_qvarnlabs_zone(f, serial)
+ filenames.append(serial_name)
elif style == 'dns-api':
- serial = None
with open(filename, 'w') as f:
write_dnsapi_zone(f, domain)
else:
assert 0
- filenames = [basename]
- if serial is not None:
- filename.append(serial)
subprocess.call(
['git', 'commit', '-m', 'automatic zone update'] + filenames,
cwd=dirname)
@@ -256,7 +261,17 @@ def write_dnsapi_zone(stream, domain):
context, info['name'], domain, info['ipv4']))
-def write_inventory_files(config, args):
+def write_inventory_files(config, context):
+ style = get_inventory_style_for_context(config, context)
+ if style == 'ipv4':
+ write_inventory_files_with_ipv4(config)
+ elif style == 'dns':
+ write_inventory_files_with_dns_names(config, context)
+ else:
+ assert 0
+
+
+def write_inventory_files_with_ipv4(config):
for context in list_contexts():
use_context(context)
dirname = get_inventorydir_for_context(config, context)
@@ -269,6 +284,20 @@ def write_inventory_files(config, args):
info['name'], info['ipv4']))
+def write_inventory_files_with_dns_names(config, context):
+ domain = get_domain_for_context(config, context)
+ for context in list_contexts():
+ use_context(context)
+ dirname = get_inventorydir_for_context(config, context)
+ filename = os.path.join(dirname, 'hosts.{}'.format(context))
+ print('Writing Ansible inventory file {}'.format(filename))
+ with open(filename, 'w') as f:
+ for info in list_servers():
+ name = dns_name(context, info['name'], domain)
+ f.write(
+ '{} ansible_ssh_host={}\n'.format(info['name'], name))
+
+
def kick_bind9(ssh_target, filename, basename):
target = '{}:/etc/bind/{}'.format(ssh_target, basename)
subprocess.check_call(['scp', filename, target])
diff --git a/ickdev.yaml b/ickdev.yaml
index dac3098..18742b3 100644
--- a/ickdev.yaml
+++ b/ickdev.yaml
@@ -2,5 +2,5 @@ defaults:
type: cx11
image: debian-9
hosts:
- - name: test
+ - name: ick
type: cx51