From 9078900dd13aa289900c0d01337909aabdcbda92 Mon Sep 17 00:00:00 2001 From: Sven Velt Date: Wed, 14 May 2025 09:13:03 +0200 Subject: [PATCH] Scripte zum Erzeugen des Inventory --- helper/create_hosts_from_file.sh | 15 +++++ helper/create_hosts_from_lxc.sh | 10 ++++ helper/create_inventory_from_file.sh | 90 ++++++++++++++++++++++++++++ helper/create_inventory_from_lxc.sh | 85 ++++++++++++++++++++++++++ 4 files changed, 200 insertions(+) create mode 100755 helper/create_hosts_from_file.sh create mode 100755 helper/create_hosts_from_lxc.sh create mode 100755 helper/create_inventory_from_file.sh create mode 100755 helper/create_inventory_from_lxc.sh diff --git a/helper/create_hosts_from_file.sh b/helper/create_hosts_from_file.sh new file mode 100755 index 0000000..7baf0e5 --- /dev/null +++ b/helper/create_hosts_from_file.sh @@ -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 + diff --git a/helper/create_hosts_from_lxc.sh b/helper/create_hosts_from_lxc.sh new file mode 100755 index 0000000..82ef68b --- /dev/null +++ b/helper/create_hosts_from_lxc.sh @@ -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 + diff --git a/helper/create_inventory_from_file.sh b/helper/create_inventory_from_file.sh new file mode 100755 index 0000000..cc1ab69 --- /dev/null +++ b/helper/create_inventory_from_file.sh @@ -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 <