added scripts and ansible stuff for easy managment

This commit is contained in:
Rasmus Thorslund 2024-05-31 18:23:21 +02:00
parent c2fd1ac9e1
commit 6749f378c2
No known key found for this signature in database
GPG key ID: 502D33332E9E305D
7 changed files with 136 additions and 0 deletions

View file

@ -0,0 +1,35 @@
[all]
internal-sto4-prod-k8sw-0.rut.sunet.se
internal-sto4-prod-k8sw-4.rut.sunet.se
internal-sto4-prod-k8sw-5.rut.sunet.se
internal-sto4-prod-k8sc-2.rut.sunet.se
internal-sto4-prod-k8sw-1.rut.sunet.se
internal-sto4-prod-satosa-1.rut.sunet.se
internal-sto4-prod-k8sw-2.rut.sunet.se
internal-sto4-prod-k8sw-3.rut.sunet.se
internal-sto4-prod-k8sc-1.rut.sunet.se
internal-sto4-prod-monitor-1.rut.sunet.se
internal-sto4-prod-k8sc-0.rut.sunet.se
[worker_nodes]
internal-sto4-prod-k8sw-0.rut.sunet.se
internal-sto4-prod-k8sw-4.rut.sunet.se
internal-sto4-prod-k8sw-5.rut.sunet.se
internal-sto4-prod-k8sw-1.rut.sunet.se
internal-sto4-prod-k8sw-2.rut.sunet.se
internal-sto4-prod-k8sw-3.rut.sunet.se
[control_nodes]
internal-sto4-prod-k8sc-2.rut.sunet.se
internal-sto4-prod-k8sc-1.rut.sunet.se
internal-sto4-prod-k8sc-0.rut.sunet.se
[satosa]
internal-sto4-prod-satosa-1.rut.sunet.se
[monitor]
internal-sto4-prod-monitor-1.rut.sunet.se

View file

@ -0,0 +1,12 @@
---
- name: Create a file to pause Cosmos
hosts: all
become: yes
tasks:
- name: Ensure the file /etc/no-automatic-cosmos exists with specific content
ansible.builtin.copy:
dest: /etc/no-automatic-cosmos
content: "Cosmos paused by Ansible\n"
owner: root
group: root
mode: '0644'

View file

@ -0,0 +1,9 @@
---
- name: Remove the file to resume Cosmos
hosts: all
become: yes
tasks:
- name: Remove the file /etc/no-automatic-cosmos if it exists
ansible.builtin.file:
path: /etc/no-automatic-cosmos
state: absent

View file

@ -0,0 +1,8 @@
---
- name: Remove root password for hosts
hosts: all
become: yes
tasks:
- name: Remove root password
ansible.builtin.command:
cmd: passwd -d root

View file

@ -0,0 +1,21 @@
---
- name: Set root password for hosts
hosts: all
become: yes
vars_prompt:
- name: "root_password"
prompt: "Enter the new root password"
private: yes
tasks:
- name: Hash the root password on localhost
delegate_to: localhost
run_once: true
become: false
set_fact:
hashed_password: "{{ root_password | password_hash('sha512') }}"
- name: Set root password on target hosts
ansible.builtin.user:
name: root
password: "{{ hashed_password }}"

11
scripts/get_knotctl_commands.sh Executable file
View file

@ -0,0 +1,11 @@
#!/bin/bash
export OS_CLOUD=sto4-rut
SERVER_LIST=$(openstack server list -f json | jq -r '.[] | {Name: .Name, IPv4: .Networks.public[] | select(test("^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$")), IPv6: .Networks.public[] | select(test("^[0-9a-fA-F:]+$"))} | [ .Name, .IPv4, .IPv6 ] | @csv' | tr -d '"')
DOMAIN="rut.sunet.se"
while IFS=',' read -r name ipv4 ipv6; do
echo "knotctl add -r A -z $DOMAIN -n $name. -d $ipv4"
echo "knotctl add -r AAAA -z $DOMAIN -n $name. -d $ipv6"
done <<< "$SERVER_LIST"

View file

@ -0,0 +1,40 @@
#!/bin/bash
SERVER_LIST=$(openstack server list -f json | jq -r '.[] | .Name')
INVENTORY_FILE="ansible_inventory.ini"
rm -f $INVENTORY_FILE
echo "[all]" > $INVENTORY_FILE
WORKER_NODES_SECTION=""
CONTROL_NODES_SECTION=""
SATOSA_SECTION=""
MONITOR_SECTION=""
while read -r name; do
echo "$name" >> $INVENTORY_FILE
if [[ $name == *k8sw* ]]; then
WORKER_NODES_SECTION+="$name\n"
elif [[ $name == *k8sc* ]]; then
CONTROL_NODES_SECTION+="$name\n"
elif [[ $name == *satosa* ]]; then
SATOSA_SECTION+="$name\n"
elif [[ $name == *monitor* ]]; then
MONITOR_SECTION+="$name\n"
fi
done <<< "$SERVER_LIST"
# Append each section to the inventory file
echo -e "\n[worker_nodes]" >> $INVENTORY_FILE
echo -e "$WORKER_NODES_SECTION" >> $INVENTORY_FILE
echo -e "\n[control_nodes]" >> $INVENTORY_FILE
echo -e "$CONTROL_NODES_SECTION" >> $INVENTORY_FILE
echo -e "\n[satosa]" >> $INVENTORY_FILE
echo -e "$SATOSA_SECTION" >> $INVENTORY_FILE
echo -e "\n[monitor]" >> $INVENTORY_FILE
echo -e "$MONITOR_SECTION" >> $INVENTORY_FILE
echo "Ansible inventory file created at $INVENTORY_FILE"