diff --git a/salt-master/files/etc/salt/master.d/reactors.conf b/salt-master/files/etc/salt/master.d/reactors.conf new file mode 100644 index 0000000..706175b --- /dev/null +++ b/salt-master/files/etc/salt/master.d/reactors.conf @@ -0,0 +1,3 @@ +reactor: + - 'salt/beacon/*/inotify//dev': + - /srv/reactor/device_reactor.sls diff --git a/salt-master/files/srv/reactor/device_reactor.sls b/salt-master/files/srv/reactor/device_reactor.sls new file mode 100644 index 0000000..bdc9e28 --- /dev/null +++ b/salt-master/files/srv/reactor/device_reactor.sls @@ -0,0 +1,16 @@ +{% set label = data['path'].split('/')[-1] -%} +{% if label in ['rfxtrx433'] -%} +{% if data['change'] == 'IN_CREATE' -%} +{% set label = label + '=true' -%} +{% else %} +{% set label = label +'-' -%} +{% endif -%} +{% set node = data['id'].split('.')[0] -%} +label_k3s_node_{{ node }}: + local.state.single: + - tgt: masters + - tgt_type: nodegroup + - args: + - fun: cmd.run + - name: "kubectl label node {{ node }} {{ label }}" +{% endif -%} diff --git a/salt-master/init.sls b/salt-master/init.sls new file mode 100644 index 0000000..7679e6d --- /dev/null +++ b/salt-master/init.sls @@ -0,0 +1,2 @@ +include: + - salt-master.reactors diff --git a/salt-master/reactors.sls b/salt-master/reactors.sls new file mode 100644 index 0000000..d21d348 --- /dev/null +++ b/salt-master/reactors.sls @@ -0,0 +1,28 @@ +Create reactors master configuration: + file.managed: + - name: /etc/salt/master.d/reactors.conf + - source: salt://salt-master/files/etc/salt/master.d/reactors.conf + - user: root + - group: root + - mode: "0644" + +restart master: + service.running: + - name: salt-master + - onchanges: + - file: Create reactors master configuration + +Create reactors directory: + file.directory: + - name: /srv/reactor + - user: root + - group: root + - mode: "0755" + +Create rfxcom reactor: + file.managed: + - name: /srv/reactor/device_reactor.sls + - source: salt://salt-master/files/srv/reactor/device_reactor.sls + - user: root + - group: root + - mode: "0644" diff --git a/top.sls b/top.sls index 047a968..5e904bf 100644 --- a/top.sls +++ b/top.sls @@ -10,6 +10,7 @@ base: 'salt.rre.nu': - dnsmasq + - salt-master 'k3s': - match: nodegroup