From 3302ba5b6088ccab49275deb23782780f45da060 Mon Sep 17 00:00:00 2001 From: Pierre Kunzli <pierre.kuenzli@unige.ch> Date: Wed, 12 Mar 2025 14:31:56 +0100 Subject: [PATCH] ajout de contenu pour les clusters k8s --- projets/netseclab/ansible/ansible.cfg | 2 + .../ansible/create_user_wst-01-08.yml | 12 +++++ .../ansible/create_user_wst-09-16.yml | 12 +++++ projets/netseclab/ansible/hosts | 49 +++++++++++++++++++ projets/netseclab/ansible/initial_setup.yml | 17 +++++++ projets/netseclab/ansible/shutdown.yml | 7 +++ projets/netseclab/create_user_wst-01-08.sh | 5 ++ projets/netseclab/create_user_wst-09-16.sh | 5 ++ projets/netseclab/hosts.txt | 16 ++++++ projets/netseclab/initial_setup.sh | 5 ++ projets/netseclab/ping.sh | 24 +++++++++ projets/netseclab/shutdown.sh | 5 ++ 12 files changed, 159 insertions(+) create mode 100644 projets/netseclab/ansible/ansible.cfg create mode 100644 projets/netseclab/ansible/create_user_wst-01-08.yml create mode 100644 projets/netseclab/ansible/create_user_wst-09-16.yml create mode 100644 projets/netseclab/ansible/hosts create mode 100644 projets/netseclab/ansible/initial_setup.yml create mode 100644 projets/netseclab/ansible/shutdown.yml create mode 100755 projets/netseclab/create_user_wst-01-08.sh create mode 100755 projets/netseclab/create_user_wst-09-16.sh create mode 100644 projets/netseclab/hosts.txt create mode 100755 projets/netseclab/initial_setup.sh create mode 100755 projets/netseclab/ping.sh create mode 100755 projets/netseclab/shutdown.sh diff --git a/projets/netseclab/ansible/ansible.cfg b/projets/netseclab/ansible/ansible.cfg new file mode 100644 index 0000000..321fe5b --- /dev/null +++ b/projets/netseclab/ansible/ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +stdout_callback=debug \ No newline at end of file diff --git a/projets/netseclab/ansible/create_user_wst-01-08.yml b/projets/netseclab/ansible/create_user_wst-01-08.yml new file mode 100644 index 0000000..c0c3e6d --- /dev/null +++ b/projets/netseclab/ansible/create_user_wst-01-08.yml @@ -0,0 +1,12 @@ +- hosts: wst-01-08 + gather_facts: true + vars_prompt: + - name: password + prompt: What is the new password? + + tasks: + - name: change user's password + become: true + ansible.builtin.user: + name: agodomou + password: '{{password}}' diff --git a/projets/netseclab/ansible/create_user_wst-09-16.yml b/projets/netseclab/ansible/create_user_wst-09-16.yml new file mode 100644 index 0000000..5108a5d --- /dev/null +++ b/projets/netseclab/ansible/create_user_wst-09-16.yml @@ -0,0 +1,12 @@ +- hosts: wst-09-16 + gather_facts: true + vars_prompt: + - name: password + prompt: What is the new password? + + tasks: + - name: change user's password + become: true + ansible.builtin.user: + name: lavorel + password: '{{password}}' diff --git a/projets/netseclab/ansible/hosts b/projets/netseclab/ansible/hosts new file mode 100644 index 0000000..c3b1043 --- /dev/null +++ b/projets/netseclab/ansible/hosts @@ -0,0 +1,49 @@ +[wst] +wst-01 ansible_host=10.78.240.1 +wst-02 ansible_host=10.78.240.2 +wst-03 ansible_host=10.78.240.3 +wst-04 ansible_host=10.78.240.4 +wst-05 ansible_host=10.78.240.5 +wst-06 ansible_host=10.78.240.6 +wst-07 ansible_host=10.78.240.7 +wst-08 ansible_host=10.78.240.8 +wst-09 ansible_host=10.78.240.9 +wst-10 ansible_host=10.78.240.10 +wst-11 ansible_host=10.78.240.11 +wst-12 ansible_host=10.78.240.12 +wst-13 ansible_host=10.78.240.13 +wst-14 ansible_host=10.78.240.14 +wst-15 ansible_host=10.78.240.15 +wst-16 ansible_host=10.78.240.16 + +[wst-01-08] +wst-01 ansible_host=10.78.240.1 +wst-02 ansible_host=10.78.240.2 +wst-03 ansible_host=10.78.240.3 +wst-04 ansible_host=10.78.240.4 +wst-05 ansible_host=10.78.240.5 +wst-06 ansible_host=10.78.240.6 +wst-07 ansible_host=10.78.240.7 +wst-08 ansible_host=10.78.240.8 + +[wst-09-16] +wst-09 ansible_host=10.78.240.9 +wst-10 ansible_host=10.78.240.10 +wst-11 ansible_host=10.78.240.11 +wst-12 ansible_host=10.78.240.12 +wst-13 ansible_host=10.78.240.13 +wst-14 ansible_host=10.78.240.14 +wst-15 ansible_host=10.78.240.15 +wst-16 ansible_host=10.78.240.16 + +[wst:vars] +ansible_port=22 +ansible_ssh_common_args='-o StrictHostKeyChecking=no' + +[wst-01-08:vars] +ansible_port=22 +ansible_ssh_common_args='-o StrictHostKeyChecking=no' + +[wst-09-16:vars] +ansible_port=22 +ansible_ssh_common_args='-o StrictHostKeyChecking=no' diff --git a/projets/netseclab/ansible/initial_setup.yml b/projets/netseclab/ansible/initial_setup.yml new file mode 100644 index 0000000..8b7d511 --- /dev/null +++ b/projets/netseclab/ansible/initial_setup.yml @@ -0,0 +1,17 @@ +- hosts: wst + gather_facts: true + vars_prompt: + - name: password + prompt: What is the new password? + + tasks: + - name: change user's password + become: true + ansible.builtin.user: + name: debian + password: '{{password}}' + - name: Update and upgrade apt packages + become: true + ansible.builtin.apt: + upgrade: yes + update_cache: yes diff --git a/projets/netseclab/ansible/shutdown.yml b/projets/netseclab/ansible/shutdown.yml new file mode 100644 index 0000000..0fd5e09 --- /dev/null +++ b/projets/netseclab/ansible/shutdown.yml @@ -0,0 +1,7 @@ +- hosts: wst + gather_facts: true + + tasks: + - name: Unconditionally shut down the machine with all defaults + become: true + community.general.shutdown: diff --git a/projets/netseclab/create_user_wst-01-08.sh b/projets/netseclab/create_user_wst-01-08.sh new file mode 100755 index 0000000..e876128 --- /dev/null +++ b/projets/netseclab/create_user_wst-01-08.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# first argument of the scrit is ansible username + +cd ansible +ansible-playbook create_user_wst-01-08.yml -u $1 -i hosts -kK diff --git a/projets/netseclab/create_user_wst-09-16.sh b/projets/netseclab/create_user_wst-09-16.sh new file mode 100755 index 0000000..65e393f --- /dev/null +++ b/projets/netseclab/create_user_wst-09-16.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# first argument of the scrit is ansible username + +cd ansible +ansible-playbook create_user_wst-09-16.yml -u $1 -i hosts -kK diff --git a/projets/netseclab/hosts.txt b/projets/netseclab/hosts.txt new file mode 100644 index 0000000..a1af16a --- /dev/null +++ b/projets/netseclab/hosts.txt @@ -0,0 +1,16 @@ +10.78.240.1 +10.78.240.2 +10.78.240.3 +10.78.240.4 +10.78.240.5 +10.78.240.6 +10.78.240.7 +10.78.240.8 +10.78.240.9 +10.78.240.10 +10.78.240.11 +10.78.240.12 +10.78.240.13 +10.78.240.14 +10.78.240.15 +10.78.240.16 diff --git a/projets/netseclab/initial_setup.sh b/projets/netseclab/initial_setup.sh new file mode 100755 index 0000000..3f92df0 --- /dev/null +++ b/projets/netseclab/initial_setup.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# first argument of the scrit is ansible username + +cd ansible +ansible-playbook initial_setup.yml -u $1 -i hosts -kK diff --git a/projets/netseclab/ping.sh b/projets/netseclab/ping.sh new file mode 100755 index 0000000..f0905b0 --- /dev/null +++ b/projets/netseclab/ping.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# File containing the list of hosts, one per line +HOSTS_FILE="hosts.txt" + +# ANSI color codes +GREEN='\033[0;32m' +RED='\033[0;31m' +NC='\033[0m' # No Color + +# Check if the hosts file exists +if [[ ! -f "$HOSTS_FILE" ]]; then + echo "Hosts file not found!" + exit 1 +fi + +# Read the hosts file and ping each host +while IFS= read -r host; do + if ping -c 1 -W 1 "$host" &> /dev/null; then + echo -e "Host ${GREEN}$host${NC} is reachable." + else + echo -e "Host ${RED}$host${NC} is not reachable." + fi +done < "$HOSTS_FILE" diff --git a/projets/netseclab/shutdown.sh b/projets/netseclab/shutdown.sh new file mode 100755 index 0000000..77dfd5f --- /dev/null +++ b/projets/netseclab/shutdown.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# first argument of the scrit is ansible username + +cd ansible +ansible-playbook shutdown.yml -u $1 -i hosts -kK -- GitLab