Rolle: proxmox - Script. start_pools.sh (#28)
Rolle erstellt Co-authored-by: Michael Grote <38253905+quotengrote@users.noreply.github.com> Reviewed-on: mg/ansible#28 Co-Authored-By: mg <michael.grote@posteo.de> Co-Committed-By: mg <michael.grote@posteo.de>
This commit is contained in:
parent
06a76ef006
commit
18d9574489
7 changed files with 43 additions and 0 deletions
|
@ -11,3 +11,4 @@
|
|||
tags: "ecc",
|
||||
when: "'pve2.grote.lan' in inventory_hostname" }
|
||||
- { role: mgrote.cv4pve-autosnap, tags: "cv4pve" }
|
||||
- { role: mgrote.proxmox, tags: "pve" }
|
||||
|
|
25
roles/mgrote.proxmox/README.md
Normal file
25
roles/mgrote.proxmox/README.md
Normal file
|
@ -0,0 +1,25 @@
|
|||
## mgrote.proxmox
|
||||
|
||||
### Beschreibung
|
||||
Installiert ein Script um komplette Poools zu starten/stoppen.
|
||||
|
||||
### Funktioniert auf
|
||||
- [x] ProxMox 6.1
|
||||
|
||||
### Variablen + Defaults
|
||||
see [defaults](./defaults/main.yml)
|
||||
|
||||
### Erklärung start_pools.sh
|
||||
#### Argumente
|
||||
`$1, $2, $n` = gleich Parameter in der Schreibreihenfolge nach dem Aufruf, also
|
||||
`./pools.sh Test start`
|
||||
`Test = $1`
|
||||
`start = $2`
|
||||
möglich: Poolnamen(case-sensitiv) & start/stop
|
||||
|
||||
#### RegEx
|
||||
`sudo pvesh get /pools/$1 |` gibt alle VM/ct-Daten als JSON(?)-Objekt mit Formatierung aus
|
||||
`sed -r 's#(,)#\n#g;s#\│##g;s#─##g;s#┴##g;s#└##g;s#┘##g;s#╞##g;s#╪##g;s#═##g;s#╡##g;s#\{##g;s#\}##g;s#\"*\"##g;s#\[##g;s#\]##g;s#id\:## g' |` erstellt Zeilenumbrüche, entfernt Formatierung, formatiert Text für grep
|
||||
`grep -E 'qemu/[[:digit:]]{3}' |` sucht alle Zeilen aus die den Typ und die VMID enthalten
|
||||
`sed -r 's#(qemu\/)([0-9]{3})#\2#g' | ` entfernt den Typ von der VMID
|
||||
`sudo xargs -i --verbose qm "$2" {}` übergibt VMIDs an das PVE-Kommando mit xargs
|
1
roles/mgrote.proxmox/defaults/main.yml
Normal file
1
roles/mgrote.proxmox/defaults/main.yml
Normal file
|
@ -0,0 +1 @@
|
|||
---
|
0
roles/mgrote.proxmox/handlers/main.yml
Normal file
0
roles/mgrote.proxmox/handlers/main.yml
Normal file
1
roles/mgrote.proxmox/meta/main.yml
Normal file
1
roles/mgrote.proxmox/meta/main.yml
Normal file
|
@ -0,0 +1 @@
|
|||
---
|
7
roles/mgrote.proxmox/tasks/main.yml
Normal file
7
roles/mgrote.proxmox/tasks/main.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
- name: copy start_pools.sh
|
||||
become: yes
|
||||
ansible.builtin.template:
|
||||
src: "start_pools.sh"
|
||||
dest: "/usr/local/bin/start_pools.sh"
|
||||
mode: a+x
|
8
roles/mgrote.proxmox/templates/start_pools.sh
Normal file
8
roles/mgrote.proxmox/templates/start_pools.sh
Normal file
|
@ -0,0 +1,8 @@
|
|||
#! /bin/bash
|
||||
{% raw %}
|
||||
# starte/stoppe Container
|
||||
sudo pvesh get /pools/$1 | sed -r 's#(,)#\n#g;s#\│##g;s#─##g;s#┴##g;s#└##g;s#┘##g;s#╞##g;s#╪##g;s#═##g;s#╡##g;s#\{##g;s#\}##g;s#\"*\"##g;s#\[##g;s#\]##g;s#id\:##g' | grep -E 'lxc/[[:digit:]]{3}' | sed -r 's#(lxc\/)([0-9]{3})#\2#g' | sudo xargs -i --verbose pct "$2" {}
|
||||
|
||||
# starte/stoppe VMs
|
||||
sudo pvesh get /pools/$1 | sed -r 's#(,)#\n#g;s#\│##g;s#─##g;s#┴##g;s#└##g;s#┘##g;s#╞##g;s#╪##g;s#═##g;s#╡##g;s#\{##g;s#\}##g;s#\"*\"##g;s#\[##g;s#\]##g;s#id\:##g' | grep -E 'qemu/[[:digit:]]{3}' | sed -r 's#(qemu\/)([0-9]{3})#\2#g' | sudo xargs -i --verbose qm "$2" {}
|
||||
{% endraw %}
|
Loading…
Reference in a new issue