diff --git a/_modules/node.py b/_modules/node.py new file mode 100644 index 0000000..976304a --- /dev/null +++ b/_modules/node.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- + +# ------------------------------------------------------------- +# Salt — Node execution module +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# Created: 2017-10-21 +# Description: Functions related to FreeBSD jails +# License: BSD-2-Clause +# ------------------------------------------------------------- + + +def _get_all_nodes(): + return __pillar__.get('nodes', {}) + + +def get(nodename=None): + ''' + A function to get a node pillar configuration. + + CLI Example: + + salt * node.get + ''' + if nodename is None: + nodename = __grains__['id'] + + all_nodes = _get_all_nodes() + return all_nodes[nodename] + + +def _explode_key(k): return k.split(':') + + +def _get_first_key(k): return _explode_key(k)[0] + + +def _strip_first_key(k): return ':'.join(_explode_key(k)[1:]) + + +def _get_property(key, nodename, default_value, parent=None): + if parent is None: + parent = get(nodename) + + if ':' in key: + first_key = _get_first_key(key) + if first_key in parent: + return _get_property( + _strip_first_key(key), nodename, + default_value, parent[first_key] + ) + elif key in parent: + return parent[key] + + return default_value + + +def list(key, nodename=None): + ''' + A function to get a node pillar configuration. + + Returns a list if found, or an empty list if not found. + + CLI Example: + + salt * node.list network:ipv4_aliases + ''' + return _get_property(key, nodename, []) + + +def has(key, nodename=None): + ''' + A function to get a node pillar configuration. + + Returns a boolean, False if not found. + + CLI Example: + + salt * node.has network:ipv6_tunnel + ''' + return _get_property(bool(key), nodename, False) diff --git a/pillar/nodes/nodes.sls b/pillar/nodes/nodes.sls index ea350bf..db2bf49 100644 --- a/pillar/nodes/nodes.sls +++ b/pillar/nodes/nodes.sls @@ -1,50 +1,55 @@ # ------------------------------------------------------------- # Salt — Nodes # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Project: Nasqueron # Created: 2017-10-20 # License: Trivial work, not eligible to copyright # ------------------------------------------------------------- nodes: ## ## Forest: Nasqueron ## Semantic field: https://devcentral.nasqueron.org/P27 ## dwellers: forest: nasqueron hostname: dwellers.nasqueron.org roles: - paas-lxc - paas-docker network: ipv6_tunnel: True equatower: forest: nasqueron hostname: equatower.nasqueron.org roles: - paas-docker network: ipv6_tunnel: False ysul: forest: nasqueron hostname: ysul.nasqueron.org roles: - devserver - saltmaster network: + ipv4_interface: igb0 + ipv4_address: 163.172.49.16 + ipv4_gateway: 163.172.49.1 + ipv4_aliases: + - 213.83.187.132 ipv6_tunnel: True ## ## Forest: Eglide ## Semantic field: ? (P27 used for "Eglide" too) ## ## This forest is intended to separate credentials ## between Eglide and Nasqueron sevrers. ## eglide: forest: eglide hostname: eglide.org roles: - shellserver network: ipv6_tunnel: True diff --git a/roles/core/network/files/netif.rc b/roles/core/network/files/netif.rc new file mode 100644 index 0000000..e604033 --- /dev/null +++ b/roles/core/network/files/netif.rc @@ -0,0 +1,23 @@ +# ------------------------------------------------------------- +# Network — rc configuration +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# Source file: roles/core/network/files/netif.rc +# ------------------------------------------------------------- +# +# <auto-generated> +# This file is managed by our rOPS SaltStack repository. +# +# Changes to this file may cause incorrect behavior +# and will be lost if the state is redeployed. +# </auto-generated> + +{% if dhcp_required %} +ifconfig_{{ interface }}="DHCP" +{% else %} +ifconfig_{{ interface }}="inet {{ ipv4_address }} netmask {{ ipv4_netmask }}" +{% endif %} +{% for ip in ipv4_aliases %} +ifconfig_{{ interface }}_alias{{ loop.index0 }}="inet {{ ip }} netmask 255.255.255.255" +{% endfor %} diff --git a/roles/core/network/files/routing.rc b/roles/core/network/files/routing.rc new file mode 100644 index 0000000..88d0eb5 --- /dev/null +++ b/roles/core/network/files/routing.rc @@ -0,0 +1,16 @@ +# ------------------------------------------------------------- +# Network — rc configuration +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# Source file: roles/core/network/files/routing.rc +# ------------------------------------------------------------- +# +# <auto-generated> +# This file is managed by our rOPS SaltStack repository. +# +# Changes to this file may cause incorrect behavior +# and will be lost if the state is redeployed. +# </auto-generated> + +defaultrouter="{{ ipv4_gateway }}" diff --git a/roles/core/network/init.sls b/roles/core/network/init.sls index fcf658f..07345fe 100644 --- a/roles/core/network/init.sls +++ b/roles/core/network/init.sls @@ -1,22 +1,49 @@ # ------------------------------------------------------------- # Salt — Network # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Project: Nasqueron # Created: 2016-06-15 # License: Trivial work, not eligible to copyright # ------------------------------------------------------------- {% from "map.jinja" import dirs with context %} +{% set network = salt['node.get']()['network'] %} + +# ------------------------------------------------------------- +# IPv4 +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +{% if grains['os'] == 'FreeBSD' %} +/etc/rc.conf.d/netif/ipv4_{{ network['ipv4_interface'] }}: + file.managed: + - source: salt://roles/core/network/files/netif.rc + - makedirs: True + - template: jinja + - context: + interface: {{ network['ipv4_interface'] }} + ipv4_address: {{ network['ipv4_address'] }} + ipv4_netmask: {{ network['ipv4_netmask'] | default('255.255.255.0') }} + ipv4_aliases: {{ salt['node.list']('network:ipv4_aliases') }} + dhcp_required: {{ salt['node.has']('network:dhcp_required') }} + +/etc/rc.conf.d/routing: + file.managed: + - source: salt://roles/core/network/files/routing.rc + - template: jinja + - context: + ipv4_gateway: {{ network['ipv4_gateway'] }} +{% endif %} + # ------------------------------------------------------------- # IPv6 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -{% if salt['pillar.get']("nodes:" + grains['id'] + ":network:ipv6_tunnel", False) %} +{% if salt['node.has']('network.ipv6_tunnel') %} network_ipv6: file.managed: - name : {{ dirs.sbin }}/ipv6-setup-tunnel - source: salt://roles/core/network/files/{{ grains['id'] }}_ipv6.sh.jinja - template: jinja - mode: 755 {% endif %} diff --git a/roles/paas-jails/jails/init.sls b/roles/paas-jails/jails/init.sls index f1a92ff..71c1541 100644 --- a/roles/paas-jails/jails/init.sls +++ b/roles/paas-jails/jails/init.sls @@ -1,62 +1,63 @@ # ------------------------------------------------------------- # Salt — Jails # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Project: Nasqueron # Notes: FreeBSD-only unit # Created: 2017-10-21 # License: Trivial work, not eligible to copyright # ------------------------------------------------------------- # ------------------------------------------------------------- # Software to manage jails # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ezjail: pkg.installed # ------------------------------------------------------------- # Configuration # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - jails_rc_jail: file.managed: - name: /etc/rc.conf.d/jail - source: salt://roles/paas-jails/jails/files/jail.rc - template: jinja - context: jails: {{ salt['jails.flatlist']() }} jails_rc_netif: file.managed: - - name: /etc/rc.conf.d/netif + - name: /etc/rc.conf.d/netif/jails + - makedirs: True - source: salt://roles/paas-jails/jails/files/netif.rc jails_rc_ezjail: file.managed: - name: /etc/rc.conf.d/ezjail - source: salt://roles/paas-jails/jails/files/ezjail.rc # ------------------------------------------------------------- # Build master jail # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - generate_basejail: cmd.run: - name: ezjail-admin install -p - creates: /usr/jails/basejail /usr/jails/newjail/etc/resolv.conf: file.managed: - source: salt://roles/paas-jails/jails/files/resolv.conf # ------------------------------------------------------------- # Build applications/services jails # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {% for jail in salt['jails.list']() %} {% set ips = salt['jails.get_ezjail_ips_parameter'](jail) %} generate_jail_{{ jail }}: cmd.run: - name: ezjail-admin create {{ jail }} {{ ips | yaml_encode }} - creates: /usr/jails/{{ jail }} {% endfor %}