Browse Source

Merge fe9bc6b45a into ca20bd6aa6

pull/79/merge
Martin Horák 6 years ago
parent
commit
24322f6f74
No account linked to committer's email address
14 changed files with 169 additions and 2 deletions
  1. +54
    -0
      README.rst
  2. +2
    -0
      metadata/service/minion/dns_register.yml
  3. +2
    -0
      metadata/service/minion/dns_static.yml
  4. +2
    -2
      salt/control/virt.sls
  5. +6
    -0
      salt/files/ddns.keyring
  6. +6
    -0
      salt/map.jinja
  7. +14
    -0
      salt/master/ddns.sls
  8. +3
    -0
      salt/master/init.sls
  9. +5
    -0
      salt/minion/dns_register.sls
  10. +5
    -0
      salt/minion/dns_static.sls
  11. +6
    -0
      salt/minion/init.sls
  12. +19
    -0
      salt/reactor/ddns_node_register.sls
  13. +19
    -0
      salt/reactor/ddns_static_records.sls
  14. +26
    -0
      tests/pillar/master_dns.sls

+ 54
- 0
README.rst View File

- host: master-of-master-host2 - host: master-of-master-host2
timeout: 5 timeout: 5


Dynamic DNS configuration
-------------------------

Salt master can register minions in DNS server using DDNS (dynamic DNS)
update mechanism via salt.runners.ddns module. DNS server with dynamic
updates allowed is required. Authorization via {tsig-key} is available.
Recommended is DNS server configured via salt-formula-bind.
Mechanism uses event-reactor system.

Master pillar:

.. code-block:: yaml

salt:
master:
ddns:
enabled: True
keys:
key: <tsig-key>
name: <tsig-key-name>
reactor:
dns/node/register:
- salt://salt/reactor/ddns_node_register.sls
dns/static/records:
- salt://salt/reactor/ddns_static_records.sls

Minion pillar:

.. code-block:: yaml

salt:
minion:
ddns:
server: <dns-server-ip>
keyname: <tsig-key-name>
ttl: 300
dns_static:
zone.example.com:
- name: appname
type: CNAME
value: appserver01


Manual calling:

.. code-block:: bash

# Minion register
salt '*' state.apply salt.minion.dns_register
#
# Static DNS records
salt '*' state.apply salt.minion.dns_static


Salt Minion Salt Minion
----------- -----------



+ 2
- 0
metadata/service/minion/dns_register.yml View File

applications:
- salt.minion.dns_register

+ 2
- 0
metadata/service/minion/dns_static.yml View File

applications:
- salt.minion.dns_static

+ 2
- 2
salt/control/virt.sls View File



{%- if cluster.engine == "virt" %} {%- if cluster.engine == "virt" %}


salt_libvirt_service:
salt_libvirt_service_{{ cluster_name }}:
service.running: service.running:
- name: {{ control.virt_service }} - name: {{ control.virt_service }}
- enable: true - enable: true
{%- endif %} {%- endif %}
- unless: virsh list --all --name| grep -E "^{{ node_name }}.{{ cluster.domain }}$" - unless: virsh list --all --name| grep -E "^{{ node_name }}.{{ cluster.domain }}$"
- require: - require:
- salt_libvirt_service
- salt_libvirt_service_{{ cluster_name }}


{%- if node.get("autostart", True) %} {%- if node.get("autostart", True) %}



+ 6
- 0
salt/files/ddns.keyring View File

{%- from "salt/map.jinja" import master with context -%}
{
{%- for key in master.ddns.get('keys', []) %}
"{{ key.name }}.": "{{ key.key }}"{{ "," if not loop.last else "" }}
{%- endfor %}
}

+ 6
- 0
salt/map.jinja View File

Arch: Arch:
pkgs: pkgs:
- salt - salt
ddns_pkgs:
- python-dnspython
Debian: Debian:
pkgs: pkgs:
- salt-master - salt-master
ddns_pkgs:
- python-dnspython
Gentoo: Gentoo:
pkgs: pkgs:
- app-admin/salt - app-admin/salt
RedHat: RedHat:
pkgs: pkgs:
- salt-master - salt-master
ddns_pkgs:
- python-dnspython
{%- endload %} {%- endload %}


{%- if pillar.salt.master is defined %} {%- if pillar.salt.master is defined %}

+ 14
- 0
salt/master/ddns.sls View File

{%- from "salt/map.jinja" import master with context %}
{%- if master.get('ddns', {}).get('enabled', False) %}
ddns_packages:
pkg.installed:
- names: {{ master.ddns_pkgs }}

ddns_keys_file:
file.managed:
- name: /etc/salt/ddns.keyring
- source: salt://salt/files/ddns.keyring
- template: jinja
- mode: 600

{%- endif %}

+ 3
- 0
salt/master/init.sls View File

{%- if pillar.salt.master.reactor is defined %} {%- if pillar.salt.master.reactor is defined %}
- salt.master.reactor - salt.master.reactor
{%- endif %} {%- endif %}
{%- if pillar.salt.master.ddns is defined %}
- salt.master.ddns
{%- endif %}
- salt.master.env - salt.master.env
- salt.master.pillar - salt.master.pillar
- salt.master.minion - salt.master.minion

+ 5
- 0
salt/minion/dns_register.sls View File

send_dns_register_event:
event.send:
- name: dns/node/register
- net_info: {{ pillar.linux.network.get('host', {}) }}
- ddns: {{ pillar.salt.minion.get('ddns', {}) }}

+ 5
- 0
salt/minion/dns_static.sls View File

send_dns_static_event:
event.send:
- name: dns/static/records
- records: {{ pillar.salt.minion.get('dns_static', {}) }}
- ddns: {{ pillar.salt.minion.get('ddns', {}) }}

+ 6
- 0
salt/minion/init.sls View File

{%- if pillar.salt.minion.env_vars is defined %} {%- if pillar.salt.minion.env_vars is defined %}
- salt.minion.env_vars - salt.minion.env_vars
{%- endif %} {%- endif %}
{%- if pillar.salt.minion.ddns is defined %}
- salt.minion.dns_register
{%- if pillar.salt.minion.dns_static is defined %}
- salt.minion.dns_static
{%- endif %}
{%- endif %}

+ 19
- 0
salt/reactor/ddns_node_register.sls View File

{%- set ddns = data.data.get('ddns', {}) %}
{%- for rec_name, record in data.data.get('net_info', {}).iteritems() %}
{%- for name in record.get('names', []) if '.' in name %}
{%- set hostname, domain = name.split('.',1) %}

ddns_node_register_{{ name }}_{{ loop.index }}:
runner.ddns.add_host:
- args:
- zone: {{ domain }}
- name: {{ hostname }}
- ttl: {{ ddns.get('ttl', 300) }}
- ip: {{ record.get('address', '127.0.0.127') }}
- keyname: {{ ddns.get('keyname', 'salt-updates') }}
- keyfile: /etc/salt/ddns.keyring
- nameserver: {{ ddns.get('server', '127.0.0.1') }}
- keyalgorithm: 'HMAC-MD5.SIG-ALG.REG.INT'
- timeout: 10
{%- endfor %}
{%- endfor %}

+ 19
- 0
salt/reactor/ddns_static_records.sls View File

{%- set ddns = data.data.get('ddns', {}) %}
{%- for zone_name, zone in data.data.get('records', {}).iteritems() %}
{%- for record in zone %}

ddns_record_{{ zone_name }}_{{ loop.index }}:
runner.ddns.create:
- args:
- zone: {{ zone_name }}
- name: {{ record['name'] }}
- ttl: {{ ddns.get('ttl', 300) }}
- rdtype: {{ record['type'] }}
- data: {{ record['value'] }}
- keyname: {{ ddns.get('keyname', 'salt-updates') }}
- keyfile: /etc/salt/ddns.keyring
- nameserver: {{ ddns.get('server', '127.0.0.1') }}
- timeout: 10
- keyalgorithm: 'HMAC-MD5.SIG-ALG.REG.INT'
{%- endfor %}
{%- endfor %}

+ 26
- 0
tests/pillar/master_dns.sls View File

git:
client:
enabled: true
linux:
system:
enabled: true
salt:
master:
enabled: true
command_timeout: 5
worker_threads: 2
reactor_worker_threads: 2
source:
engine: pkg
pillar:
engine: salt
source:
engine: local
ddns:
enabled: True
keys:
key: 'yEdG9/x8Sb+efi27GyeXNg=='
name: salt-updates
reactor:
dns/node/register:
- salt://salt/reactor/node_ddns_register.sls

Loading…
Cancel
Save