]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
add manag_records.rb
authorRobert Waffen <rwaffen@gmail.com>
Mon, 22 Jun 2020 08:58:02 +0000 (10:58 +0200)
committerRobert Waffen <rwaffen@gmail.com>
Mon, 22 Jun 2020 08:58:02 +0000 (10:58 +0200)
13 files changed:
.gitignore
Gemfile [new file with mode: 0644]
Gemfile.lock [new file with mode: 0644]
README.md
etc/dns/dev_bmas.yaml [new file with mode: 0644]
etc/dns/dev_bmf.yaml [new file with mode: 0644]
etc/dns/dev_tst.yaml [new file with mode: 0644]
etc/dns/live_bmas.yaml [new file with mode: 0644]
etc/dns/live_bmf.yaml [new file with mode: 0644]
etc/dns/test_bmas.yaml [new file with mode: 0644]
etc/dns/test_bmf.yaml [new file with mode: 0644]
sbin/Readme.md [new file with mode: 0644]
sbin/manage_records.rb [new file with mode: 0755]

index 8f4ea9d5f93b8f672fb8823c5ddd2bb469800a03..4914459f8fe665c425117d7a48793a65bffbdb1f 100644 (file)
@@ -10,3 +10,6 @@ MANIFEST
 *.egg-info
 .idea
 *.whl
+
+.bundle/
+vendor/
diff --git a/Gemfile b/Gemfile
new file mode 100644 (file)
index 0000000..8f2a63c
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,3 @@
+source 'https://rubygems.org' do
+  gem 'net-ssh', '>=5.2.0'
+end
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644 (file)
index 0000000..656b86f
--- /dev/null
@@ -0,0 +1,13 @@
+GEM
+  remote: https://rubygems.org/
+  specs:
+    net-ssh (5.2.0)
+
+PLATFORMS
+  ruby
+
+DEPENDENCIES
+  net-ssh (>= 5.2.0)!
+
+BUNDLED WITH
+   2.0.1
index 863db1dac82947bd33b37f88e5d64145e341ee6b..22f48d0e1705b7715fa28f6c6b2e319080c91605 100644 (file)
--- a/README.md
+++ b/README.md
@@ -78,12 +78,18 @@ Die Installation von zusätzlichen Modulen mittels pip im System sollte unbeding
 Wenn doch Module verwendet werden müssen, für die es kein Betriebssystem-Paket gibt, dann muss ein
 Virtual Environment für Python eingerichtet und verwendet werden.
 
+### Ruby-Scripte
+
+Ruby Scripte definieren ihre Abhängkieten im Gemfile. Scripte die Gems verwenden sollten mit Bundler
+arbeiten. Dies benötigt Internetzugang. Bundles sollten local installiert werden und nicht global.
+`bundle install --path vendor/gems` - Der Pfad wird dabei selbst angelegt. `vendor/` ist in der
+`.gitignore` eingetragen. Es sollte nach möglichkeit immer `optparse` verwendet werden.
+
 ## Autor
 
 Frank Brehm <frank.brehm@pixelpark.com>
+Robert Waffen <robert.waffen@pixelpark.com>
 
 ## Stand
 
-18.03.2019
-
-
+22.06.2020
diff --git a/etc/dns/dev_bmas.yaml b/etc/dns/dev_bmas.yaml
new file mode 100644 (file)
index 0000000..7de5165
--- /dev/null
@@ -0,0 +1,48 @@
+---
+dev-bmas10:
+  - dev-standardlsg-preview-bmas10
+  - dev-standardlsg-editor-bmas10
+  - dev-standardlsg-www-bmas10
+  - dev-bmas-preview-bmas10
+  - dev-bmas-editor-bmas10
+  - dev-bmas-www-bmas10
+  - dev-repository-preview-bmas10
+  - dev-editor-preview-bmas10
+  - dev-service-preview-bmas10
+  - dev-solr-preview-bmas10
+  - dev-delivery-preview-bmas10
+  - dev-workflow-preview-bmas10
+  - dev-newsletter-preview-bmas10
+  - dev-repository-master-bmas10
+  - dev-service-master-bmas10
+  - dev-solr-master-bmas10
+  - dev-delivery1-master-bmas10
+  - dev-delivery2-master-bmas10
+  - dev-repository-replication-bmas10
+  - dev-solr-replication-bmas10
+  - dev-delivery1-replication-bmas10
+  - dev-delivery2-replication-bmas10
+  - dev-adminportal-database-bmas10
+  - dev-site-database-bmas10
+  - dev-preview-database-bmas10
+  - dev-master-database-bmas10
+  - dev-replication-database-bmas10
+  - dev-maildistributor-database-bmas10
+  - dev-workflow-database-bmas10
+  - dev-adminportal-service-bmas10
+  - dev-serviceportal-service-bmas10
+  - dev-maildistributor-service-bmas10
+  - dev-cas-preview-service-bmas10
+  - dev-cas-live-service-bmas10
+  - dev-ldap-preview-service-bmas10
+  - dev-ldap-live-service-bmas10
+  - dev-mail-extern-bmas10
+  - dev-esf-preview-bmas10
+  - dev-esf-editor-bmas10
+  - dev-esf-www-bmas10
+  - dev-inqa-preview-bmas10
+  - dev-inqa-editor-bmas10
+  - dev-inqa-www-bmas10
+  - dev-bmas2020-preview-bmas10
+  - dev-bmas2020-editor-bmas10
+  - dev-bmas2020-www-bmas10
diff --git a/etc/dns/dev_bmf.yaml b/etc/dns/dev_bmf.yaml
new file mode 100644 (file)
index 0000000..61b35f4
--- /dev/null
@@ -0,0 +1,54 @@
+---
+dev-bmf10:
+  - dev-standardlsg-preview-bmf10
+  - dev-standardlsg-editor-bmf10
+  - dev-standardlsg-www-bmf10
+  - dev-bmf-preview-bmf10
+  - dev-bmf-editor-bmf10
+  - dev-bmf-www-bmf10
+  - dev-amthb-preview-bmf10
+  - dev-amthb-editor-bmf10
+  - dev-amthb-www-bmf10
+  - dev-lsth-preview-bmf10
+  - dev-lsth-www-bmf10
+  - dev-esth-preview-bmf10
+  - dev-esth-www-bmf10
+  - dev-ksth-preview-bmf10
+  - dev-ksth-www-bmf10
+  - dev-gewsth-preview-bmf10
+  - dev-gewsth-www-bmf10
+  - dev-repository-preview-bmf10
+  - dev-editor-preview-bmf10
+  - dev-service-preview-bmf10
+  - dev-solr-preview-bmf10
+  - dev-delivery-preview-bmf10
+  - dev-workflow-preview-bmf10
+  - dev-newsletter-preview-bmf10
+  - dev-repository-master-bmf10
+  - dev-service-master-bmf10
+  - dev-solr-master-bmf10
+  - dev-delivery1-master-bmf10
+  - dev-delivery2-master-bmf10
+  - dev-repository-replication-bmf10
+  - dev-solr-replication-bmf10
+  - dev-delivery1-replication-bmf10
+  - dev-delivery2-replication-bmf10
+  - dev-adminportal-database-bmf10
+  - dev-site-database-bmf10
+  - dev-preview-database-bmf10
+  - dev-master-database-bmf10
+  - dev-replication-database-bmf10
+  - dev-maildistributor-database-bmf10
+  - dev-workflow-database-bmf10
+  - dev-adminportal-service-bmf10
+  - dev-serviceportal-service-bmf10
+  - dev-maildistributor-service-bmf10
+  - dev-cas-preview-service-bmf10
+  - dev-cas-live-service-bmf10
+  - dev-ldap-preview-service-bmf10
+  - dev-ldap-live-service-bmf10
+  - dev-mail-extern-bmf10
+  - dev-usth-preview-bmf10
+  - dev-usth-www-bmf10
+  - dev-ao-preview-bmf10
+  - dev-ao-www-bmf10
diff --git a/etc/dns/dev_tst.yaml b/etc/dns/dev_tst.yaml
new file mode 100644 (file)
index 0000000..83220fc
--- /dev/null
@@ -0,0 +1,4 @@
+---
+www:
+  - robert
+  - waffen
diff --git a/etc/dns/live_bmas.yaml b/etc/dns/live_bmas.yaml
new file mode 100644 (file)
index 0000000..fbf7a25
--- /dev/null
@@ -0,0 +1,73 @@
+---
+master01-bmas10-de:
+  - master-database-bmas10
+  - repository-master-bmas10
+  - service-master-bmas10
+  - site-database-bmas10
+  - solr-master-bmas10
+
+red-bmas10-de:
+  - adminportal-database-bmas10
+  - adminportal-service-bmas10
+  - amthb-editor-bmas10
+  - amthb-preview-bmas10
+  - bmas-editor-bmas10
+  - bmas-preview-bmas10
+  - cas-live-service-bmas10
+  - cas-preview-service-bmas10
+  - delivery-preview-bmas10
+  - editor-preview-bmas10
+  - maildistributor-database-bmas10
+  - maildistributor-service-bmas10
+  - newsletter-preview-bmas10
+  - preview-database-bmas10
+  - repository-preview-bmas10
+  - service-preview-bmas10
+  - serviceportal-service-bmas10
+  - solr-preview-bmas10
+  - workflow-database-bmas10
+  - workflow-preview-bmas10
+  - ldap-preview-service-bmas10
+  - ldap-live-service-bmas10
+  - esf-preview-bmas10
+  - esf-editor-bmas10
+  - inqa-preview-bmas10
+  - inqa-editor-bmas10
+  - bmas2020-preview-bmas10
+  - bmas2020-editor-bmas10
+
+slave01-bmas10-de:
+  - replication-database-bmas10
+  - repository-replication-bmas10
+
+www01-bmas10-de:
+  - bmas-www01-bmas10
+  - delivery1-master-bmas10
+  - esf-www01-bmas10
+  - inqa-www01-bmas10
+  - bmas2020-www01-bmas10
+
+www02-bmas10-de:
+  - bmas-www02-bmas10
+  - delivery2-master-bmas10
+  - esf-www02-bmas10
+  - inqa-www02-bmas10
+  - bmas2020-www02-bmas10
+
+www03-bmas10-de:
+  - bmas-www03-bmas10
+  - delivery1-replication-bmas10
+  - esf-www03-bmas10
+  - inqa-www03-bmas10
+  - bmas2020-www03-bmas10
+
+www04-bmas10-de:
+  - bmas-www04-bmas10
+  - delivery2-replication-bmas10
+  - esf-www04-bmas10
+  - inqa-www04-bmas10
+  - bmas2020-www04-bmas10
+
+bmas-www-bmas10:
+  # - inqa-www-bmas10
+  - bmas2020-www-bmas10
diff --git a/etc/dns/live_bmf.yaml b/etc/dns/live_bmf.yaml
new file mode 100644 (file)
index 0000000..e30b0a1
--- /dev/null
@@ -0,0 +1,92 @@
+---
+master01-bmf10-de:
+  - master-database-bmf10
+  - repository-master-bmf10
+  - service-master-bmf10
+  - site-database-bmf10
+  - solr-master-bmf10
+
+red-bmf10-de:
+  - adminportal-database-bmf10
+  - adminportal-service-bmf10
+  - amthb-editor-bmf10
+  - amthb-preview-bmf10
+  - ao-preview-bmf10
+  - bmf-editor-bmf10
+  - bmf-preview-bmf10
+  - cas-live-service-bmf10
+  - cas-preview-service-bmf10
+  - delivery-preview-bmf10
+  - editor-preview-bmf10
+  - esth-preview-bmf10
+  - gewsth-preview-bmf10
+  - ksth-preview-bmf10
+  - lsth-preview-bmf10
+  - maildistributor-database-bmf10
+  - maildistributor-service-bmf10
+  - newsletter-preview-bmf10
+  - preview-database-bmf10
+  - repository-preview-bmf10
+  - service-preview-bmf10
+  - serviceportal-service-bmf10
+  - solr-preview-bmf10
+  - usth-preview-bmf10
+  - workflow-database-bmf10
+  - workflow-preview-bmf10
+
+slave01-bmf10-de:
+  - replication-database-bmf10
+  - repository-replication-bmf10
+
+www01-bmf10-de:
+  - amthb-www01-bmf10
+  - ao-www01-bmf10
+  - bmf-www01-bmf10
+  - delivery1-master-bmf10
+  - esth-www01-bmf10
+  - gewsth-www01-bmf10
+  - ksth-www01-bmf10
+  - lsth-www01-bmf10
+  - usth-www01-bmf10
+
+www02-bmf10-de:
+  - amthb-www02-bmf10
+  - ao-www02-bmf10
+  - bmf-www02-bmf10
+  - delivery2-master-bmf10
+  - esth-www02-bmf10
+  - gewsth-www02-bmf10
+  - ksth-www02-bmf10
+  - lsth-www02-bmf10
+  - usth-www02-bmf10
+
+www03-bmf10-de:
+  - amthb-www03-bmf10
+  - ao-www03-bmf10
+  - bmf-www03-bmf10
+  - delivery1-replication-bmf10
+  - esth-www03-bmf10
+  - gewsth-www03-bmf10
+  - ksth-www03-bmf10
+  - lsth-www03-bmf10
+  - usth-www03-bmf10
+
+www04-bmf10-de:
+  - amthb-www04-bmf10
+  - ao-www04-bmf10
+  - bmf-www04-bmf10
+  - delivery2-replication-bmf10
+  - esth-www04-bmf10
+  - gewsth-www04-bmf10
+  - ksth-www04-bmf10
+  - lsth-www04-bmf10
+  - usth-www04-bmf10
+
+bmf-www-bmf10:
+  - amthb-www-bmf10
+  - ao-www-bmf10
+  - esth-www-bmf10
+  - gewsth-www-bmf10
+  - ksth-www-bmf10
+  - lsth-www-bmf10
+  - usth-www-bmf10
diff --git a/etc/dns/test_bmas.yaml b/etc/dns/test_bmas.yaml
new file mode 100644 (file)
index 0000000..24ae007
--- /dev/null
@@ -0,0 +1,59 @@
+---
+test-master01-bmas10-de:
+  - test-master-database-bmas10
+  - test-site-database-bmas10
+  - test-repository-master-bmas10
+  - test-service-master-bmas10
+  - test-solr-master-bmas10
+
+test-red-bmas10-de:
+  - test-preview-database-bmas10
+  - test-adminportal-database-bmas10
+  - test-maildistributor-database-bmas10
+  - test-workflow-database-bmas10
+  - test-adminportal-service-bmas10
+  - test-cas-preview-service-bmas10
+  - test-cas-live-service-bmas10
+  - test-service-preview-bmas10
+  - test-solr-preview-bmas10
+  - test-maildistributor-service-bmas10
+  - test-editor-preview-bmas10
+  - test-workflow-preview-bmas10
+  - test-repository-preview-bmas10
+  - test-delivery-preview-bmas10
+  - test-newsletter-preview-bmas10
+  - test-serviceportal-service-bmas10
+  - test-bmas-preview-bmas10
+  - test-bmas-editor-bmas10
+  - test-ldap-preview-service-bmas10
+  - test-ldap-live-service-bmas10
+  - test-esf-preview-bmas10
+  - test-esf-editor-bmas10
+  - test-inqa-preview-bmas10
+  - test-inqa-editor-bmas10
+  - test-bmas2020-preview-bmas10
+  - test-bmas2020-editor-bmas10
+
+test-slave01-bmas10-de:
+  - test-replication-database-bmas10
+  - test-repository-replication-bmas10
+
+test-www01-bmas10-de:
+  - test-delivery1-master-bmas10
+  - test-bmas-www01-bmas10
+  - test-bmas-www01-bmas10
+  - test-esf-www01-bmas10
+  - test-inqa-www01-bmas10
+  - test-bmas2020-www01-bmas10
+
+test-www02-bmas10-de:
+  - test-delivery1-replication-bmas10
+  - test-bmas-www02-bmas10
+  - test-bmas-www02-bmas10
+  - test-esf-www02-bmas10
+  - test-inqa-www02-bmas10
+  - test-bmas2020-www02-bmas10
+
+test-bmas-www-bmas10:
+  - test-inqa-www-bmas10
+  - test-bmas2020-www-bmas10
diff --git a/etc/dns/test_bmf.yaml b/etc/dns/test_bmf.yaml
new file mode 100644 (file)
index 0000000..6b2b63e
--- /dev/null
@@ -0,0 +1,78 @@
+---
+test-master01-bmf10-de:
+  - test-master-database-bmf10
+  - test-site-database-bmf10
+  - test-repository-master-bmf10
+  - test-service-master-bmf10
+  - test-solr-master-bmf10
+
+test-red-bmf10-de:
+  - test-preview-database-bmf10
+  - test-adminportal-database-bmf10
+  - test-maildistributor-database-bmf10
+  - test-workflow-database-bmf10
+  - test-adminportal-service-bmf10
+  - test-cas-preview-service-bmf10
+  - test-cas-live-service-bmf10
+  - test-service-preview-bmf10
+  - test-solr-preview-bmf10
+  - test-maildistributor-service-bmf10
+  - test-editor-preview-bmf10
+  - test-workflow-preview-bmf10
+  - test-repository-preview-bmf10
+  - test-delivery-preview-bmf10
+  - test-newsletter-preview-bmf10
+  - test-serviceportal-service-bmf10
+  - test-bmf-preview-bmf10
+  - test-bmf-editor-bmf10
+  - test-ldap-preview-service-bmf10
+  - test-ldap-live-service-bmf10
+
+# customer
+  - test-bmf-preview-bmf10
+  - test-lsth-preview-bmf10
+  - test-amthb-preview-bmf10
+  - test-esth-preview-bmf10
+  - test-ksth-preview-bmf10
+  - test-gewsth-preview-bmf10
+  - test-usth-preview-bmf10
+  - test-ao-preview-bmf10
+  - test-bmf-editor-bmf10
+  - test-amthb-editor-bmf10
+
+test-slave01-bmf10-de:
+  - test-replication-database-bmf10
+  - test-repository-replication-bmf10
+
+test-www01-bmf10-de:
+  - test-delivery1-master-bmf10
+  - test-bmf-www01-bmf10
+  - test-bmf-www01-bmf10
+  - test-amthb-www01-bmf10
+  - test-lsth-www01-bmf10
+  - test-esth-www01-bmf10
+  - test-ksth-www01-bmf10
+  - test-gewsth-www01-bmf10
+  - test-usth-www01-bmf10
+  - test-ao-www01-bmf10
+
+test-www02-bmf10-de:
+  - test-delivery1-replication-bmf10
+  - test-bmf-www02-bmf10
+  - test-bmf-www02-bmf10
+  - test-amthb-www02-bmf10
+  - test-lsth-www02-bmf10
+  - test-esth-www02-bmf10
+  - test-ksth-www02-bmf10
+  - test-gewsth-www02-bmf10
+  - test-usth-www02-bmf10
+  - test-ao-www02-bmf10
+
+test-bmf-www-bmf10:
+  - test-amthb-www-bmf10
+  - test-ao-www-bmf10
+  - test-esth-www-bmf10
+  - test-gewsth-www-bmf10
+  - test-ksth-www-bmf10
+  - test-lsth-www-bmf10
+  - test-usth-www-bmf10
diff --git a/sbin/Readme.md b/sbin/Readme.md
new file mode 100644 (file)
index 0000000..22aaa94
--- /dev/null
@@ -0,0 +1,31 @@
+# Scripts
+
+## bin/manage_records.rb
+
+Das script setzt anhand von yaml dateien cnames auf vorhandene a records
+
+yaml format in `etc/dns`:
+
+    ---
+    ein_a_record:
+      - ein_cname
+      - zwei_cnames
+
+    zweiter_a_records:
+      - drei_cnames
+
+Die bisherig config liegt hier im projekt in etc/dns/\*.yaml
+
+Ausführung:
+
+    # einmalig zum installieren der abhängkieten
+    bundle install --path vendor/gems
+
+    # Benutzung
+    bundle exec ruby bin/manage_records.rb --help
+
+    # bei jeder änderung der yaml files dann auszuführen
+    bundle exec ruby bin/manage_records.rb --data etc/dns/test_bmas.yaml
+
+    # mehr output
+    bundle exec ruby bin/manage_records.rb --data etc/dns/dev_bmas.yaml --debug
diff --git a/sbin/manage_records.rb b/sbin/manage_records.rb
new file mode 100755 (executable)
index 0000000..e1cc265
--- /dev/null
@@ -0,0 +1,77 @@
+#!/usr/bin/env ruby
+
+require 'net/ssh'
+require 'optparse'
+require 'pp'
+require 'resolv'
+require 'yaml'
+
+################################################################################
+
+# default options
+@options = {
+  zone: 'pixelpark.net',
+  user: 'robert.waffen'
+}
+
+OptionParser.new do |opts|
+  opts.on("--user=USER_NAME", "Username for SSH Session") { |user|  @options[:user]  = user  }
+  opts.on("--data=YAML_PATH", "local path to config yaml") { |data|  @options[:data]  = data  }
+  opts.on("--zone=ZONE_NAME", "DNS Zone name to add records to") { |zone|  @options[:zone]  = zone  }
+  opts.on("--debug", TrueClass) { |debug| @options[:debug] = debug.nil? ? true : debug  }
+  opts.on_tail("-h", "--help", "Show this message") do
+    puts opts
+    puts "Defaults: #{@options}"
+    exit
+  end
+end.parse!
+
+################################################################################
+
+action      = 'add-record'
+data        = YAML.load_file(@options[:data])
+debug       = @options[:debug]
+pdns_cmds   = []
+record_type = "CNAME"
+ssh_output  = []
+ttl         = "3600"
+user        = @options[:user]
+zone        = @options[:zone]
+@dnsmaster   = "dnsmaster.pp-dns.com"
+
+################################################################################
+
+def check_rr_set(rrset)
+  Resolv::DNS.open({:nameserver=>[@dnsmaster]}) do |r|
+    r.getaddresses(rrset)
+  end
+end
+
+data.map do |key, value|
+  puts "canme target: #{key}" if debug
+
+  value.each do |cname|
+    puts "cname is #{cname}.#{zone}" if debug
+    test_record = check_rr_set "#{cname}.#{zone}"
+    pp test_record if debug
+
+    if test_record.empty?
+      pdns_cmds << "pdnsutil #{action} #{zone} #{cname} #{record_type} #{ttl} #{key}.#{zone}."
+    end
+  end
+end
+
+unless pdns_cmds.empty?
+  pdns_cmds << "pdnsutil increase-serial #{zone}"
+  pdns_cmds << "pdns_control notify #{zone}"
+end
+
+puts pdns_cmds if debug
+
+Net::SSH.start(@dnsmaster, user) do |ssh|
+  pdns_cmds.each do |command|
+    ssh_output << ssh.exec!("sudo #{command}")
+  end
+end
+
+puts ssh_output