]> xn--ix-yja.es Git - alex.git/commitdiff
Initial add
authoralex <alex@pdp7.net>
Wed, 1 Feb 2023 20:16:20 +0000 (21:16 +0100)
committeralex <alex@pdp7.net>
Wed, 1 Feb 2023 20:16:20 +0000 (21:16 +0100)
personal_infra/playbooks/roles/apply_puppet/tasks/main.yml
personal_infra/pseudo_resource_exporter.py [new file with mode: 0755]
personal_infra/puppet/modules/automatic_updates/manifests/init.pp
personal_infra/puppet/modules/nagios_core
personal_infra/puppet/site/00-common.pp

index 3512717ee2763185fa46cc320d97892cfe6d455b..831d5b94908f611f21ef92f765c8f340201a54de 100644 (file)
     cmd: "{{ inventory_dir }}/up.py {{ inventory_dir }}/build/puppet {{ inventory_dir }}/puppet/modules {{ inventory_dir }}/puppet/site {% for host in ansible_play_batch %}{{ host }} {% endfor %}"
   tags: puppet_fast
   run_once: True
+- name: simulate exported resources
+  local_action:
+    module: command
+    cmd: "./pseudo_resource_exporter.py"
+    chdir: "{{ inventory_dir }}"
+  tags: puppet_fast
+  run_once: True
 - name: package catalog
   archive:
     path: "{{ inventory_dir }}/build/puppet/build/output/{{ inventory_hostname }}"
diff --git a/personal_infra/pseudo_resource_exporter.py b/personal_infra/pseudo_resource_exporter.py
new file mode 100755 (executable)
index 0000000..0753a0d
--- /dev/null
@@ -0,0 +1,69 @@
+#!/usr/bin/env python3
+
+import json
+import pathlib
+
+
+def load_json(path):
+    with open(path) as f:
+        return json.load(f)
+
+def save_json(r, path):
+    with open(path, "w") as f:
+        json.dump(r, f)
+
+nagios_catalog_file = pathlib.Path("build/puppet/build/output/nagios.h1.int.pdp7.net/catalog.json")
+
+if nagios_catalog_file.exists():
+    nagios_catalog = load_json(nagios_catalog_file)
+
+    nagios_contacts = [r for r in nagios_catalog["resources"] if r["type"] == "Nagios_contact"]
+    assert len(nagios_contacts) == 1, f"found multiple nagios contacts {nagios_contacts}"
+    nagios_contact = nagios_contacts[0]
+
+total_hosts_in_inventory = len(list(pathlib.Path("host_vars").glob("*")))
+
+catalog_files = list(pathlib.Path("build/puppet/build/output/").glob("*/catalog.json"))
+
+if nagios_catalog_file.exists():
+    assert len(catalog_files) == total_hosts_in_inventory, f"catalogs {catalog_files} quantity different from total hosts in inventory {total_hosts_in_inventory}"
+
+
+nagios_resources = []
+nagios_edge_targets = []
+
+def is_nagios_resource(r):
+    return r["type"].startswith("Nagios")
+
+
+def is_nagios_edge(e):
+    return e["target"].startswith("Nagios")
+
+for catalog_file in catalog_files:
+    if catalog_file == nagios_catalog_file:
+        continue
+    catalog = load_json(catalog_file)
+    nagios_resources += [r for r in catalog["resources"] if is_nagios_resource(r)]
+    catalog["resources"] = [r for r in catalog["resources"] if not is_nagios_resource(r)]
+    nagios_edge_targets += [e["target"] for e in catalog["edges"] if is_nagios_edge(e)]
+    catalog["edges"] = [e for e in catalog["edges"] if not is_nagios_edge(e)]
+    save_json(catalog, catalog_file)
+    
+
+if nagios_catalog_file.exists():
+    nagios_contact_position = nagios_catalog["resources"].index(nagios_contact)
+
+    def copy_parameters(r):
+        for p in ["require", "notify", "owner"]:
+            r["parameters"][p] = nagios_contact["parameters"][p]
+        return r
+
+    nagios_catalog["resources"] = (
+        nagios_catalog["resources"][0:nagios_contact_position] +
+        list(map(copy_parameters, nagios_resources)) +
+        nagios_catalog["resources"][nagios_contact_position:]
+    )
+
+    nagios_catalog["edges"] += [{"source": "Class[Nagios]", "target": t} for t in nagios_edge_targets]
+
+    save_json(nagios_catalog, nagios_catalog_file)
index eed91aa0af711dbb30503a388644cc0208f5a1d8..8585b0aef45a545d35d3e9901e940b46f8f2c45c 100644 (file)
@@ -15,7 +15,7 @@ class automatic_updates {
         enable => true,
       }
     }
-    elsif ($facts['os']['release']['major'] == '8') {
+    elsif ($facts['os']['release']['major'] == '8' or $facts['os']['release']['major'] == '9') {
       package {'dnf-automatic':}
       ->
       service {'dnf-automatic-install.timer':
index 5d0a6c2bbc82ea3dd84b3a09680ec01461ff637c..8dbf9f12383bd29973963a52968b2850d98292ff 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 5d0a6c2bbc82ea3dd84b3a09680ec01461ff637c
+Subproject commit 8dbf9f12383bd29973963a52968b2850d98292ff
index f60988dc4c55d32560a1f633ff9e6ca145360891..3fa0dc1516de1f60a02b07472c89bf49ef107afe 100644 (file)
@@ -5,3 +5,19 @@ include root_mail
 if $facts['os']['family'] == "Debian" {
   class {'debian':}
 }
+
+$nagios_host = $facts['networking']['fqdn']
+
+nagios_host {$nagios_host:
+  use => 'generic-host',
+  address => $facts['networking']['fqdn'],
+  max_check_attempts => 5,
+  contact_groups => "admins",
+}
+
+nagios_service {"${nagios_host}-ssh":
+  use => 'generic-service',
+  host_name => $facts['networking']['fqdn'],
+  service_description => "ssh",
+  check_command => "check_ssh",
+}