added etcd state
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2023-09-02 17:20:54 +02:00
parent 369bb998f9
commit 934da68bb5
10 changed files with 154 additions and 0 deletions

13
states/etcd/config.sls Normal file
View File

@ -0,0 +1,13 @@
---
{%- from "etcd/map.jinja" import etcd with context %}
etcd-config-dir:
file.directory:
- name: /etc/etcd
etcd-config:
file.managed:
- name: /etc/etcd/etcd.yml
- source: salt://etcd/templates/etcd.yml.j2
- template: jinja
- watch_in:
- service: etcd-service

20
states/etcd/defaults.yaml Normal file
View File

@ -0,0 +1,20 @@
---
etcd:
enabled: true
install_dir: /usr/local/apps
release_dir: /usr/local/apps/releases
mirror: https://github.com/etcd-io/etcd/releases/download
version: 3.5.9
os: linux
arch: amd64
runuser: etcd
user: user
password: password
verify: false
config:
name: etcd
data-dir: /var/lib/etcd
initial-advertise-peer-urls: http://sys99.paulbsd.com:2380
advertise-client-urls: http://sys99.paulbsd.com:2379
listen-peer-urls: http://[::]:2380
listen-client-urls: http://[::]:2379

5
states/etcd/init.sls Normal file
View File

@ -0,0 +1,5 @@
---
include:
- .install
- .config
- .service

41
states/etcd/install.sls Normal file
View File

@ -0,0 +1,41 @@
---
{%- from "etcd/map.jinja" import etcd with context %}
etcd-user:
user.present:
- name: {{ etcd.runuser }}
- shell: /bin/nologin
etcd-archive-extract:
archive.extracted:
- name: {{ etcd.release_dir }}/etcd-{{ etcd.version }}
- source: {{ etcd.mirror }}/v{{ etcd.version }}/etcd-v{{ etcd.version }}-{{ etcd.os }}-{{ etcd.arch }}.tar.gz
- user: {{ etcd.runuser }}
- enforce_toplevel: false
- skip_verify: true
- archive_format: tar
- options: --strip 1
- if_missing: {{ etcd.release_dir }}/etcd-{{ etcd.version }}
- watch_in:
- service: etcd-service
etcd-bin-symlink:
file.symlink:
- name: {{ etcd.install_dir }}/etcd
- target: {{ etcd.release_dir }}/etcd-{{ etcd.version }}
- user: {{ etcd.runuser }}
- force: true
- watch_in:
- service: etcd-service
etcd-data-dir:
file.directory:
- name: {{ etcd.config.get('data-dir') }}
- user: {{ etcd.runuser }}
- watch_in:
- service: etcd-service
etcd-cleanup:
software.cleanup:
- name: etcd
- path: {{ etcd.release_dir }}
- version: "{{ etcd.version }}"

View File

@ -0,0 +1,3 @@
---
Linux:
os: "linux"

14
states/etcd/map.jinja Normal file
View File

@ -0,0 +1,14 @@
{%- import_yaml "etcd/defaults.yaml" as default_settings -%}
{%- import_yaml "etcd/kernelmap.yaml" as kernelmap %}
{%- import_yaml "etcd/osarchmap.yaml" as osarchmap %}
{%- set defaults = salt['grains.filter_by'](default_settings,
default='etcd',
merge=salt['grains.filter_by'](osarchmap, grain='osarch',
merge=salt['grains.filter_by'](kernelmap, grain='kernel')
)
)
-%}
{%- set etcd = salt['pillar.get']('etcd', default=defaults, merge=True) -%}

View File

@ -0,0 +1,21 @@
---
amd64:
arch: "amd64"
x86_64:
arch: "amd64"
386:
arch: "386"
arm64:
arch: "arm64"
aarch64:
arch: "arm64"
armv7l:
arch: "armv7"
armhf:
arch: "armv7"

16
states/etcd/service.sls Normal file
View File

@ -0,0 +1,16 @@
---
{%- from "etcd/map.jinja" import etcd with context %}
etcd-service-file:
file.managed:
- name: /etc/systemd/system/etcd.service
- source: salt://etcd/templates/etcd.service.j2
- user: root
- group: root
- template: jinja
- watch_in:
- service: etcd-service
etcd-service:
service.running:
- name: etcd
- enable: true

View File

@ -0,0 +1,17 @@
{%- from "etcd/map.jinja" import etcd with context -%}
## {{ salt['pillar.get']('salt_managed', default='Salt Managed') }}
[Unit]
Description=Distributed reliable key-value store for the most critical data of a distributed system
Documentation=https://etcd.io/
After=network.target
[Service]
ExecStart={{ etcd.install_dir }}/etcd/etcd --config-file /etc/etcd/etcd.yml
ExecReload=/bin/kill -HUP $MAINPID
KillMode=control-group
Restart=on-failure
RestartForceExitStatus=SIGPIPE
WorkingDirectory=/var/lib/etcd
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,4 @@
## {{ salt['pillar.get']('salt_managed', default='Salt Managed') }}
---
{%- from "etcd/map.jinja" import etcd with context %}
{{ etcd.config|yaml(False) }}