Svens Extra-Scripts/-Beispiele

This commit is contained in:
Sven Velt 2024-09-20 15:59:46 +02:00
parent b86303068a
commit 2e35e881f3
17 changed files with 329 additions and 0 deletions

View file

@ -0,0 +1,18 @@
---
- hosts:
- tn00-debian12
- tn00-alpine3i
gather_facts: no
tasks:
- name: "Gebe CHANGED zurück, wenn /etc/hostname den String 'debian' enthält"
command: cat /etc/hostname
register: output
changed_when: '"debian" in output.stdout'
- name: "Gebe FAILED zurück, wenn /etc/hostname den String 'alpine' enthält"
command: cat /etc/hostname
register: output
failed_when: '"alpine" in output.stdout'

9
extra/changed_when.yml Normal file
View file

@ -0,0 +1,9 @@
---
- hosts: all
gather_facts: no
tasks:
- command: cat /etc/hosts
register: output
changed_when: '"tn00-cento" in output.stdout'

View file

@ -0,0 +1,26 @@
---
- hosts:
- tn00-debian12
- tn00-alpine3i
gather_facts: no
tasks:
- name: Debian bricht ab
debug:
msg: "Hallo"
failed_when: '"debian" in inventory_hostname'
- hosts:
- tn00-debian12
- tn00-alpine3i
gather_facts: no
tasks:
- name: "Wer lebt noch?"
debug:
msg: "Lebenszeichen"

View file

@ -0,0 +1,8 @@
---
- hosts: localhost
gather_facts: no
tasks:
- shell: "[ ! -f wg.pub ] && wg genkey | tee wg.priv | wg pubkey | tee wg.pub || true"
register: output
changed_when: output.stdout != ""

View file

@ -0,0 +1,8 @@
---
- hosts: localhost
gather_facts: no
tasks:
- shell: "wg genkey | tee wg.priv | wg pubkey | tee wg.pub"
args:
creates: wg.pub

11
helper/06_gitmodules.sh Executable file
View file

@ -0,0 +1,11 @@
#!/bin/bash -ex
mkdir -p roles.extern
git submodule add https://git.velt.biz/Ansible/cleanup-hosts.git roles.extern/cleanup-hosts
git submodule add https://git.velt.biz/Ansible/role.ssh-keyonly.git roles.extern/ssh-keyonly
git submodule add https://git.velt.biz/Ansible/epel-simplified roles.extern/epel-simplified
ln -s cleanup-hosts roles.extern/hosts
ln -s epel-simplified roles.extern/epel

7
helper/07_gitmodules.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/bash -ex
mkdir -p roles.extern
git submodule add https://git.velt.biz/Ansible/dokuwiki_inventory.git roles.extern/dokuwiki_inventory
git submodule add -b devel https://git.velt.biz/Ansible/dokuwiki_inventory.git roles.extern/dokuwiki_inventory.devel

4
helper/07_packages.sh Executable file
View file

@ -0,0 +1,4 @@
#!/bin/bash
sudo apt install --no-install-recommends --yes python3-netaddr

5
helper/08_packages.sh Executable file
View file

@ -0,0 +1,5 @@
#!/bin/bash
sudo apt install --no-install-recommends --yes \
python3-dnspython \

8
helper/09_gitmodules.sh Executable file
View file

@ -0,0 +1,8 @@
#!/bin/bash -ex
mkdir -p roles.extern
rm -fr 09/ssh-wrapper-for-monitoring
git submodule add https://git.velt.biz/Ansible/monitored.git roles.extern/monitored
git submodule add https://git.velt.biz/Monitoring/ssh-wrapper-for-monitoring.git 09/ssh-wrapper-for-monitoring

12
helper/11_gitmodules.sh Executable file
View file

@ -0,0 +1,12 @@
#!/bin/bash -ex
mkdir -p roles.extern
git submodule add https://git.velt.biz/Ansible/roles.webcluster.git roles.webcluster
git submodule add https://git.velt.biz/Ansible/selfsignedcert.git roles.extern/selfsignedcert
cd roles.webcluster
git submodule init
git submodule update
cd ..

7
helper/12_gitmodules.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/bash -ex
mkdir -p roles.extern
git submodule add https://git.velt.biz/Ansible/roles_timesync.git roles.extern/roles_timesync
git submodule add https://git.velt.biz/Ansible/Prepare_Workshop.git 12/Prepare_Workshop

6
helper/12_packages.sh Executable file
View file

@ -0,0 +1,6 @@
#!/bin/bash
sudo apt install --no-install-recommends --yes \
jq \
nmap\

View file

@ -0,0 +1,15 @@
#!/bin/bash
if [ -z "$1" -o ! -f "$1" ]; then
echo Need filename
exit 1
fi
for GROUP in alpine archlinux centos debian devuan fedora oracle opensuse ubuntu voidlinux
do
grep "${GROUP}" "$1" | while read NAME IP REST
do
echo -e "${IP}\t${NAME}.heinlein.akademie\t\t${NAME}"
done
done

10
helper/create_hosts_from_lxc.sh Executable file
View file

@ -0,0 +1,10 @@
#!/bin/bash
for GROUP in alpine archlinux centos debian devuan fedora oracle opensuse ubuntu voidlinux
do
sudo lxc-ls -f -F name,ipv4 -g ${GROUP} | grep -v NAME | while read NAME IP
do
echo -e "${IP}\t${NAME}.heinlein.akademie\t\t${NAME}"
done
done

View file

@ -0,0 +1,90 @@
#!/bin/bash
if [ -z "$1" -o ! -f "$1" ]; then
echo Need filename
exit 1
fi
for GROUP in almalinux alpine archlinux centos debian devuan fedora oracle rockylinux opensuse ubuntu voidlinux
do
echo "[${GROUP}]"
grep "${GROUP}" "$1" | while read NAME IP REST
do
case "${GROUP}" in
almalinux|rockylinux)
echo -e "${NAME}\t\tansible_host=${IP}"
;;
*)
echo "${NAME}"
;;
esac
done
echo ""
done
cat <<EOF
############################################################
[apk:children]
alpine
[apt]
EOF
grep "mint" "$1" | while read NAME IP REST
do
echo "${NAME}"
done
cat <<EOF
[apt:children]
debian
devuan
ubuntu
[pacman:children]
archlinux
[yum:children]
almalinux
centos
fedora
oracle
rockylinux
[xbps:children]
voidlinux
[zypper:children]
opensuse
############################################################
[lb]
tn00-alpine3j
tn00-alpine3k
[lb:vars]
ansible_ssh_transfer_method=piped
[worker]
tn00-ubu2004a
tn00-ubu2004b
tn00-ubu2004c
tn00-ubu2004d
tn00-debian11
[db]
tn00-ubu2004a
tn00-ubu2004b
[webcluster:children]
lb
worker
db
EOF

View file

@ -0,0 +1,85 @@
#!/bin/bash
for GROUP in almalinux alpine archlinux centos debian devuan fedora oracle rockylinux opensuse ubuntu voidlinux
do
echo "[${GROUP}]"
sudo lxc-ls -f -F name,ipv4 -g ${GROUP} | grep -v NAME | while read NAME IP
do
case "${GROUP}" in
almalinux|rockylinux)
echo -e "${NAME}\t\tansible_host=${IP}"
;;
*)
echo "${NAME}"
;;
esac
done
echo ""
done
cat <<EOF
############################################################
[apk:children]
alpine
[apt]
EOF
sudo lxc-ls -f -F name,ipv4 -g mint | grep -v NAME | while read NAME IP
do
echo "${NAME}"
done
cat <<EOF
[apt:children]
debian
devuan
ubuntu
[pacman:children]
archlinux
[yum:children]
almalinux
centos
fedora
oracle
rockylinux
[xbps:children]
voidlinux
[zypper:children]
opensuse
############################################################
[lb]
tn00-alpine3j
tn00-alpine3k
[lb:vars]
ansible_ssh_transfer_method=piped
[worker]
tn00-ubu2004a
tn00-ubu2004b
tn00-ubu2004c
tn00-ubu2004d
tn00-debian11
[db]
tn00-ubu2004a
tn00-ubu2004b
[webcluster:children]
lb
worker
db
EOF