added cleanup on softwares
This commit is contained in:
parent
0fc13c478d
commit
b24f1f849b
18
states/_modules/software.py
Normal file
18
states/_modules/software.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import re
|
||||||
|
import os
|
||||||
|
|
||||||
|
def cleanup(name=None, path=None, version=None):
|
||||||
|
res = []
|
||||||
|
version = version.replace(".", "\.")
|
||||||
|
keep_pattern = f"^{name}-(?!{version}).*$"
|
||||||
|
regex = re.compile(keep_pattern)
|
||||||
|
for f in os.listdir(path):
|
||||||
|
if regex.match(f):
|
||||||
|
to_remove = f"{path}/{f}"
|
||||||
|
res.append(to_remove)
|
||||||
|
__salt__["file.remove"](to_remove)
|
||||||
|
if len(res) > 1:
|
||||||
|
return res
|
||||||
|
return None
|
13
states/_states/software.py
Normal file
13
states/_states/software.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
def cleanup(name=None, path=None, version=None):
|
||||||
|
ret = {'name': name,
|
||||||
|
'changes': {},
|
||||||
|
'result': True,
|
||||||
|
'comment': 'No changes been made'}
|
||||||
|
|
||||||
|
res = __salt__['software.cleanup'](name, path, version)
|
||||||
|
if res is not None:
|
||||||
|
ret['changes']["folders"] = res
|
||||||
|
|
||||||
|
return ret
|
@ -2,17 +2,23 @@
|
|||||||
{%- from "golang/map.jinja" import golang with context %}
|
{%- from "golang/map.jinja" import golang with context %}
|
||||||
golang-archive-extract:
|
golang-archive-extract:
|
||||||
archive.extracted:
|
archive.extracted:
|
||||||
- name: {{ golang.release_dir }}/go{{ golang.version }}
|
- name: {{ golang.release_dir }}/go-{{ golang.version }}
|
||||||
- source: {{ golang.mirror }}/go{{ golang.version }}.{{ golang.os }}-{{ golang.arch }}.tar.gz
|
- source: {{ golang.mirror }}/go{{ golang.version }}.{{ golang.os }}-{{ golang.arch }}.tar.gz
|
||||||
- skip_verify: true
|
- skip_verify: true
|
||||||
- enforce_toplevel: false
|
- enforce_toplevel: false
|
||||||
- options: --transform 's/^go\///g'
|
- options: --transform 's/^go\///g'
|
||||||
- if_missing: {{ golang.release_dir }}/go{{ golang.version }}
|
- if_missing: {{ golang.release_dir }}/go-{{ golang.version }}
|
||||||
|
|
||||||
golang-binary-symlink:
|
golang-binary-symlink:
|
||||||
file.symlink:
|
file.symlink:
|
||||||
- name: {{ golang.install_dir }}/go
|
- name: {{ golang.install_dir }}/go
|
||||||
- target: {{ golang.release_dir }}/go{{ golang.version }}
|
- target: {{ golang.release_dir }}/go-{{ golang.version }}
|
||||||
- force: true
|
- force: true
|
||||||
- require:
|
- require:
|
||||||
- archive: golang-archive-extract
|
- archive: golang-archive-extract
|
||||||
|
|
||||||
|
golang-cleanup:
|
||||||
|
software.cleanup:
|
||||||
|
- name: go
|
||||||
|
- path: {{ golang.release_dir }}
|
||||||
|
- version: {{ golang.version }}
|
||||||
|
@ -34,6 +34,12 @@ influxdb-archive-extract:
|
|||||||
- watch_in:
|
- watch_in:
|
||||||
- service: influxdb-service
|
- service: influxdb-service
|
||||||
|
|
||||||
|
influxdb-cleanup:
|
||||||
|
software.cleanup:
|
||||||
|
- name: influxdb
|
||||||
|
- path: {{ influxdb.release_dir }}
|
||||||
|
- version: {{ influxdb.version }}
|
||||||
|
|
||||||
influxdb-bin-symlink:
|
influxdb-bin-symlink:
|
||||||
file.symlink:
|
file.symlink:
|
||||||
- name: {{ influxdb.install_dir }}/influxdb
|
- name: {{ influxdb.install_dir }}/influxdb
|
||||||
|
@ -4,6 +4,6 @@ lego:
|
|||||||
install_dir: /usr/local/apps
|
install_dir: /usr/local/apps
|
||||||
release_dir: /usr/local/apps/releases
|
release_dir: /usr/local/apps/releases
|
||||||
mirror: https://github.com/go-acme/lego/releases/download
|
mirror: https://github.com/go-acme/lego/releases/download
|
||||||
version: v4.0.1
|
version: 4.0.1
|
||||||
os: linux
|
os: linux
|
||||||
arch: amd64
|
arch: amd64
|
||||||
|
@ -1,19 +1,23 @@
|
|||||||
---
|
---
|
||||||
{%- from "lego/map.jinja" import lego with context %}
|
{%- from "lego/map.jinja" import lego with context %}
|
||||||
{%- if not salt['file.file_exists']( lego.install_dir +"/lego-" + lego.version) %}
|
|
||||||
lego-archive-extract:
|
lego-archive-extract:
|
||||||
archive.extracted:
|
archive.extracted:
|
||||||
- name: {{ lego.release_dir }}/lego-{{ lego.version }}-{{ lego.os }}-{{ lego.arch }}
|
- name: {{ lego.release_dir }}/lego-{{ lego.version }}
|
||||||
- source: {{ lego.mirror }}/{{ lego.version }}/lego_{{ lego.version }}_{{ lego.os }}_{{ lego.arch }}.tar.gz
|
- source: {{ lego.mirror }}/v{{ lego.version }}/lego_v{{ lego.version }}_{{ lego.os }}_{{ lego.arch }}.tar.gz
|
||||||
- skip_verify: true
|
- skip_verify: true
|
||||||
- enforce_toplevel: false
|
- enforce_toplevel: false
|
||||||
- if_missing: {{ lego.release_dir }}/lego-{{ lego.version }}-{{ lego.os }}-{{ lego.arch }}
|
- if_missing: {{ lego.release_dir }}/lego-{{ lego.version }}
|
||||||
|
|
||||||
lego-binary-symlink:
|
lego-binary-symlink:
|
||||||
file.symlink:
|
file.symlink:
|
||||||
- name: /usr/local/bin/lego
|
- name: /usr/local/bin/lego
|
||||||
- target: {{ lego.release_dir }}/lego-{{ lego.version }}-{{ lego.os }}-{{ lego.arch }}/lego
|
- target: {{ lego.release_dir }}/lego-{{ lego.version }}/lego
|
||||||
- force: true
|
- force: true
|
||||||
- require:
|
- require:
|
||||||
- archive: lego-archive-extract
|
- archive: lego-archive-extract
|
||||||
{%- endif %}
|
|
||||||
|
lego-cleanup:
|
||||||
|
software.cleanup:
|
||||||
|
- name: lego
|
||||||
|
- path: {{ lego.release_dir }}
|
||||||
|
- version: {{ lego.version }}
|
||||||
|
@ -18,8 +18,14 @@ nextcloud-install-link:
|
|||||||
- target: {{ nextcloud.release_dir }}/nextcloud-{{ nextcloud.version }}
|
- target: {{ nextcloud.release_dir }}/nextcloud-{{ nextcloud.version }}
|
||||||
- force: true
|
- force: true
|
||||||
|
|
||||||
|
nextcloud-cleanup:
|
||||||
|
software.cleanup:
|
||||||
|
- name: nextcloud
|
||||||
|
- path: {{ nextcloud.release_dir }}
|
||||||
|
- version: {{ nextcloud.version }}
|
||||||
|
|
||||||
nextcloud-datadirectory:
|
nextcloud-datadirectory:
|
||||||
file.directory:
|
file.directory:
|
||||||
- name: {{ nextcloud.config.datadirectory}}
|
- name: {{ nextcloud.config.datadirectory }}
|
||||||
- user: {{ nextcloud.user }}
|
- user: {{ nextcloud.user }}
|
||||||
- group: {{ nextcloud.group }}
|
- group: {{ nextcloud.group }}
|
||||||
|
@ -17,6 +17,12 @@ pycharm-link:
|
|||||||
- target: {{ pycharm.release_dir }}/pycharm-community-{{ pycharm.version }}
|
- target: {{ pycharm.release_dir }}/pycharm-community-{{ pycharm.version }}
|
||||||
- force: true
|
- force: true
|
||||||
|
|
||||||
|
pycharm-cleanup:
|
||||||
|
software.cleanup:
|
||||||
|
- name: pycharm-community
|
||||||
|
- path: {{ pycharm.release_dir }}
|
||||||
|
- version: {{ pycharm.version }}
|
||||||
|
|
||||||
pycharm-shortcut:
|
pycharm-shortcut:
|
||||||
file.managed:
|
file.managed:
|
||||||
- name: /usr/share/applications/jetbrains-pycharm-ce.desktop
|
- name: /usr/share/applications/jetbrains-pycharm-ce.desktop
|
||||||
|
@ -18,3 +18,9 @@ qrz-binary-symlink:
|
|||||||
- archive: qrz-archive-extract
|
- archive: qrz-archive-extract
|
||||||
- watch_in:
|
- watch_in:
|
||||||
- service: qrz-service
|
- service: qrz-service
|
||||||
|
|
||||||
|
qrz-cleanup:
|
||||||
|
software.cleanup:
|
||||||
|
- name: qrz
|
||||||
|
- path: {{ qrz.release_dir }}
|
||||||
|
- version: {{ qrz.version }}
|
||||||
|
@ -4,6 +4,6 @@ rclone:
|
|||||||
install_dir: /usr/local/apps
|
install_dir: /usr/local/apps
|
||||||
release_dir: /usr/local/apps/releases
|
release_dir: /usr/local/apps/releases
|
||||||
mirror: https://downloads.rclone.org
|
mirror: https://downloads.rclone.org
|
||||||
version: v1.50.2
|
version: 1.50.2
|
||||||
os: linux
|
os: linux
|
||||||
arch: amd64
|
arch: amd64
|
||||||
|
@ -3,15 +3,21 @@
|
|||||||
rclone-archive-extract:
|
rclone-archive-extract:
|
||||||
archive.extracted:
|
archive.extracted:
|
||||||
- name: {{ rclone.release_dir }}
|
- name: {{ rclone.release_dir }}
|
||||||
- source: {{ rclone.mirror }}/{{ rclone.version }}/rclone-{{ rclone.version }}-{{ rclone.os }}-{{ rclone.arch }}.zip
|
- source: {{ rclone.mirror }}/v{{ rclone.version }}/rclone-v{{ rclone.version }}-{{ rclone.os }}-{{ rclone.arch }}.zip
|
||||||
- skip_verify: true
|
- skip_verify: true
|
||||||
- enforce_toplevel: false
|
- enforce_toplevel: false
|
||||||
- if_missing: {{ rclone.release_dir }}/rclone-{{ rclone.version }}-{{ rclone.os }}-{{ rclone.arch }}/rclone
|
- if_missing: {{ rclone.release_dir }}/rclone-v{{ rclone.version }}-{{ rclone.os }}-{{ rclone.arch }}/rclone
|
||||||
|
|
||||||
rclone-binary-symlink:
|
rclone-binary-symlink:
|
||||||
file.symlink:
|
file.symlink:
|
||||||
- name: /usr/local/bin/rclone
|
- name: /usr/local/bin/rclone
|
||||||
- target: {{ rclone.release_dir }}/rclone-{{ rclone.version }}-{{ rclone.os }}-{{ rclone.arch }}/rclone
|
- target: {{ rclone.release_dir }}/rclone-v{{ rclone.version }}-{{ rclone.os }}-{{ rclone.arch }}/rclone
|
||||||
- force: true
|
- force: true
|
||||||
- require:
|
- require:
|
||||||
- archive: rclone-archive-extract
|
- archive: rclone-archive-extract
|
||||||
|
|
||||||
|
rclone-cleanup:
|
||||||
|
software.cleanup:
|
||||||
|
- name: rclone
|
||||||
|
- path: {{ rclone.release_dir }}
|
||||||
|
- version: v{{ rclone.version }}
|
||||||
|
@ -2,18 +2,25 @@
|
|||||||
{%- from "syncthing/map.jinja" import syncthing with context %}
|
{%- from "syncthing/map.jinja" import syncthing with context %}
|
||||||
syncthing-archive-extract:
|
syncthing-archive-extract:
|
||||||
archive.extracted:
|
archive.extracted:
|
||||||
- name: {{ syncthing.release_dir }}
|
- name: {{ syncthing.release_dir }}/syncthing-{{ syncthing.version }}
|
||||||
- source: {{ syncthing.mirror }}/v{{ syncthing.version }}/syncthing-{{ syncthing.os }}-{{ syncthing.arch }}-v{{ syncthing.version }}.tar.gz
|
- source: {{ syncthing.mirror }}/v{{ syncthing.version }}/syncthing-{{ syncthing.os }}-{{ syncthing.arch }}-v{{ syncthing.version }}.tar.gz
|
||||||
- enforce_toplevel: false
|
- enforce_toplevel: false
|
||||||
- skip_verify: true
|
- skip_verify: true
|
||||||
- archive_format: tar
|
- archive_format: tar
|
||||||
- if_missing: {{ syncthing.release_dir }}/syncthing-{{ syncthing.os }}-{{ syncthing.arch }}-v{{ syncthing.version }}
|
- options: --transform 's/syncthing-{{ syncthing.os }}-{{ syncthing.arch }}-v{{ syncthing.version }}/syncthing-{{ syncthing.version }}/g' --strip 1
|
||||||
|
- if_missing: {{ syncthing.release_dir }}/syncthing-{{ syncthing.version }}
|
||||||
- watch_in:
|
- watch_in:
|
||||||
- service: syncthing-service
|
- service: syncthing-service
|
||||||
|
|
||||||
syncthing-bin-symlink:
|
syncthing-bin-symlink:
|
||||||
file.symlink:
|
file.symlink:
|
||||||
- name: {{ syncthing.install_dir }}/syncthing
|
- name: {{ syncthing.install_dir }}/syncthing
|
||||||
- target: {{ syncthing.release_dir }}/syncthing-{{ syncthing.os }}-{{ syncthing.arch }}-v{{ syncthing.version }}
|
- target: {{ syncthing.release_dir }}/syncthing-{{ syncthing.version }}
|
||||||
- watch_in:
|
- watch_in:
|
||||||
- service: syncthing-service
|
- service: syncthing-service
|
||||||
|
|
||||||
|
syncthing-cleanup:
|
||||||
|
software.cleanup:
|
||||||
|
- name: syncthing
|
||||||
|
- path: {{ syncthing.release_dir }}
|
||||||
|
- version: {{ syncthing.version }}
|
@ -29,3 +29,9 @@ telegraf-defaults-file:
|
|||||||
- template: jinja
|
- template: jinja
|
||||||
- watch_in:
|
- watch_in:
|
||||||
- service: telegraf-service
|
- service: telegraf-service
|
||||||
|
|
||||||
|
telegraf-cleanup:
|
||||||
|
software.cleanup:
|
||||||
|
- name: telegraf
|
||||||
|
- path: {{ telegraf.release_dir }}
|
||||||
|
- version: {{ telegraf.version }}
|
||||||
|
@ -46,4 +46,10 @@ telegram-shortcut:
|
|||||||
- mode: 644
|
- mode: 644
|
||||||
- template: jinja
|
- template: jinja
|
||||||
- require:
|
- require:
|
||||||
- archive: telegram-archive-extract
|
- archive: telegram-archive-extract
|
||||||
|
|
||||||
|
telegram-cleanup:
|
||||||
|
software.cleanup:
|
||||||
|
- name: telegram
|
||||||
|
- path: {{ telegram.release_dir }}
|
||||||
|
- version: {{ telegram.version }}
|
Loading…
Reference in New Issue
Block a user