diff --git a/.gitignore b/.gitignore index dad4c03..914f5f8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ ios_devices/device_backups linux-ubuntu/.DS_Store ios_devices/.DS_Store .DS_Store +home_linux/downloads/* \ No newline at end of file diff --git a/home_linux/config_files/status.sh b/home_linux/config_files/status.sh new file mode 100644 index 0000000..80f1e72 --- /dev/null +++ b/home_linux/config_files/status.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)" +let secs=$((${upSeconds}%60)) +let mins=$((${upSeconds}/60%60)) +let hours=$((${upSeconds}/3600%24)) +let days=$((${upSeconds}/86400)) +UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"` + +# get the load averages +read one five fifteen rest < /proc/loadavg + +echo "$(tput setaf 2) + .~~. .~~. `date +"%A, %e %B %Y, %r"` + '. \ ' ' / .' `uname -srmo`$(tput setaf 1) + .~ .~~~..~. + : .~.'~'.~. : Uptime.............: ${UPTIME} + ~ ( ) ( ) ~ Memory.............: `cat /proc/meminfo | grep MemFree | awk {'print $2'}`kB (Free) / `cat /proc/meminfo | grep MemTotal | awk {'print $2'}`kB (Total) +( : '~'.~.'~' : ) Load Averages......: ${one}, ${five}, ${fifteen} (1, 5, 15 min) + ~ .~ ( ) ~. ~ Running Processes..: `ps ax | wc -l | tr -d " "` + ( : '~' : ) IP Addresses.......: `ip addr | grep inet | awk ' /'192'/ { print $2 }'` and `wget -q -O - http://ipecho.net/plain | tail` + '~ .~~~. ~' Weather............: `curl -s "http://rss.accuweather.com/rss/liveweather_rss.asp?metric=1&locCode=EUR|UK|UK001|NAILSEA|" | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'` + '~' +$(tput sgr0)" \ No newline at end of file diff --git a/home_linux/disable_swap.yml b/home_linux/disable_swap.yml new file mode 100644 index 0000000..7bfe451 --- /dev/null +++ b/home_linux/disable_swap.yml @@ -0,0 +1,17 @@ +--- +- name: Disable swap on Raspberries + hosts: all + roles: + - common + become: yes + gather_facts: no + + tasks: + + - name: Disable swap + ansible.builtin.shell: sudo swapoff -a + + - name: Reboot + ansible.builtin.reboot: + test_command: uptime + diff --git a/home_linux/get_logs.yml b/home_linux/get_logs.yml index 55b5dd2..7ea3c35 100644 --- a/home_linux/get_logs.yml +++ b/home_linux/get_logs.yml @@ -4,6 +4,7 @@ roles: - common become: yes + gather_facts: no tasks: @@ -14,7 +15,7 @@ - name: Copy the log files fetch: src: /var/log/{{ item }} - dest: /mnt/c/Ansible/fetched_logs + dest: ./downloads/{{ inventory_hostname }}/ with_items: "{{ files_to_copy.stdout_lines }}" diff --git a/home_linux/get_status.yml b/home_linux/get_status.yml index ba64bfd..e4219d5 100644 --- a/home_linux/get_status.yml +++ b/home_linux/get_status.yml @@ -4,11 +4,20 @@ roles: - common become: yes + gather_facts: no tasks: + - name: Ensure status script is present + ansible.builtin.copy: + src: ./config_files/status.sh + dest: ./status.sh + owner: "{{ ansible_user }}" + group: "{{ ansible_user }}" + mode: '0755' + - name: Get device information - command: bash /home/vlad/status.sh + command: ./status.sh register: status - name: Print device information diff --git a/home_linux/home_inventory.yml b/home_linux/home_inventory.yml index bb78fea..56e21c5 100644 --- a/home_linux/home_inventory.yml +++ b/home_linux/home_inventory.yml @@ -1,9 +1,16 @@ -home: - hosts: - 192.168.0.50: - 192.168.0.51: - 192.168.0.52: - 192.168.0.53: - 192.168.0.54: +all: + children: + kubernetes: + hosts: + 192.168.0.51: + 192.168.0.52: + 192.168.0.53: + docker: + hosts: + 192.168.0.50: + zero: + hosts: + 192.168.0.54: + 192.168.0.55: vars: ansible_ssh_private_key_file = /home/vraducanu/.ssh/id_rsa diff --git a/home_linux/install_docker.yml b/home_linux/install_docker.yml new file mode 100644 index 0000000..28d70aa --- /dev/null +++ b/home_linux/install_docker.yml @@ -0,0 +1,65 @@ +--- +- name: Install Docker on Raspberries + hosts: docker + roles: + - common + become: yes + gather_facts: no + + tasks: + + - name: Download Docker install script + ansible.builtin.get_url: + url: https://test.docker.com/ + dest: ./get-docker.sh + group: "{{ ansible_user }}" + mode: '0755' + + - name: Trigger script + ansible.builtin.command: + cmd: ./get-docker.sh >> get-docker.log + + - name: Ensure group "docker" exists + ansible.builtin.group: + name: docker + state: present + + - name: Add user to "docker" group + ansible.builtin.user: + name: "{{ ansible_user }}" + group: docker + + - name: Reboot + ansible.builtin.reboot: + msg: "Reboot initiated by Ansible" + + - name: Install python3 and pip3 + ansible.builtin.apt: + pkg: + - python3 + - python3-pip + state: present + + - name: Install docker-compose + ansible.builtin.command: + cmd: sudo pip3 install docker-compose + + - name: Enable Docker service + ansible.builtin.systemd: + name: docker + enabled: yes + + - name: Run test container to ensure Docker works + ansible.builtin.command: + cmd: docker run hello-world + register: result + + - name: Show test result + ansible.builtin.debug: + var: result + + - name: Cleanup install files + ansible.builtin.command: + cmd: sudo rm get-docker.* + + \ No newline at end of file diff --git a/home_linux/install_microk8s.yml b/home_linux/install_microk8s.yml new file mode 100644 index 0000000..cb87472 --- /dev/null +++ b/home_linux/install_microk8s.yml @@ -0,0 +1,38 @@ +--- +- name: Install MicroK8s on Raspberries + hosts: kubernetes + roles: + - common + become: yes + gather_facts: no + + tasks: + + - name: Install MicroK8s + ansible.builtin.snap: + channel: stable + classic: true + name: microk8s + state: present + register: result + + - name: Display install outcome + ansible.builtin.debug: + var: result.stdout_lines + + - name: Install kubectl + ansible.builtin.snap: + channel: stable + classic: true + name: kubectl + state: present + + - name: Create kubectl config folder + ansible.builtin.file: + path: ~/.kube + state: directory + mode: "0644" + + - name: Populate kubectl config file + ansible.builtin.command: + cmd: sudo microk8s config > ~/.kube/config \ No newline at end of file diff --git a/home_linux/remove_microk8s.yml b/home_linux/remove_microk8s.yml new file mode 100644 index 0000000..f6c8f30 --- /dev/null +++ b/home_linux/remove_microk8s.yml @@ -0,0 +1,19 @@ +--- +- name: Remove MicroK8s from Raspberries + hosts: kubernetes + roles: + - common + become: yes + gather_facts: no + + tasks: + + - name: Uninstall MicroK8s + community.general.snap: + name: microk8s + state: absent + register: result + + - name: Display uninstall outcome + ansible.builtin.debug: + var: result.stdout_lines \ No newline at end of file diff --git a/home_linux/update_apt.yml b/home_linux/update_apt.yml index 739dce9..8a2e6e8 100644 --- a/home_linux/update_apt.yml +++ b/home_linux/update_apt.yml @@ -36,7 +36,7 @@ verbosity: 0 - name: Get interface configuration - shell: "ifconfig" + shell: "ip addr" register: my_interfaces - name: Print interface information