From 96dccef450ef2d13863c600bea8cf60331e6949b Mon Sep 17 00:00:00 2001 From: Danny Bessems Date: Fri, 22 Jul 2022 09:38:03 +0200 Subject: [PATCH] Housekeeping;Add tty console message --- .../files/ansible_payload/playbook.yml | 1 + .../roles/cleanup/tasks/main.yml | 14 +------ .../roles/metacluster/tasks/main.yml | 12 +++--- .../ansible_payload/roles/tty/tasks/main.yml | 20 ++++++++++ .../files/ansible_payload/templates/tty.j2 | 40 +++++++++++++++++++ ansible/roles/os/tasks/cloud-init.yml | 1 + ansible/roles/os/tasks/snapd.yml | 3 ++ ansible/roles/os/tasks/tty.yml | 7 +++- 8 files changed, 78 insertions(+), 20 deletions(-) create mode 100644 ansible/roles/firstboot/files/ansible_payload/roles/tty/tasks/main.yml create mode 100644 ansible/roles/firstboot/files/ansible_payload/templates/tty.j2 diff --git a/ansible/roles/firstboot/files/ansible_payload/playbook.yml b/ansible/roles/firstboot/files/ansible_payload/playbook.yml index f011cc5..8dffbaf 100644 --- a/ansible/roles/firstboot/files/ansible_payload/playbook.yml +++ b/ansible/roles/firstboot/files/ansible_payload/playbook.yml @@ -11,4 +11,5 @@ - users - disks - metacluster + - tty - cleanup diff --git a/ansible/roles/firstboot/files/ansible_payload/roles/cleanup/tasks/main.yml b/ansible/roles/firstboot/files/ansible_payload/roles/cleanup/tasks/main.yml index 2cca9ac..09129e1 100644 --- a/ansible/roles/firstboot/files/ansible_payload/roles/cleanup/tasks/main.yml +++ b/ansible/roles/firstboot/files/ansible_payload/roles/cleanup/tasks/main.yml @@ -2,19 +2,7 @@ ansible.builtin.cron: name: firstboot state: absent -- name: Restore extra tty - ansible.builtin.lineinfile: - path: /etc/systemd/logind.conf - regexp: "{{ item.regexp }}" - line: "{{ item.line }}" - loop: - - { regexp: '^NAutoVTs=', line: '#NAutoVTs=6'} - - { regexp: '^ReserveVT=', line: '#ReserveVT=6'} -- name: Unmask getty@tty1 service - ansible.builtin.systemd: - name: getty@tty1 - enabled: yes - masked: no + - name: Reboot host ansible.builtin.shell: cmd: /usr/sbin/reboot now diff --git a/ansible/roles/firstboot/files/ansible_payload/roles/metacluster/tasks/main.yml b/ansible/roles/firstboot/files/ansible_payload/roles/metacluster/tasks/main.yml index 514fa34..8e66d40 100644 --- a/ansible/roles/firstboot/files/ansible_payload/roles/metacluster/tasks/main.yml +++ b/ansible/roles/firstboot/files/ansible_payload/roles/metacluster/tasks/main.yml @@ -93,6 +93,7 @@ # TODO: Make this list dynamic - git - gitops + - ingress - registry - storage @@ -133,11 +134,6 @@ chdir: /opt/metacluster/container-images/ loop: "{{ imagetarballs.files }}" -- name: Delete container image tarballs/archives - ansible.builtin.file: - path: /opt/metacluster/container-images - state: absent - - name: Configure K3s node for private registry ansible.builtin.template: dest: /etc/rancher/k3s/registries.yaml @@ -334,6 +330,12 @@ status_code: [200, 201] body_format: json +- name: Delete container image tarballs/archives + ansible.builtin.file: + path: "{{ item }}" + state: absent + with_fileglob: /opt/metacluster/container-images/*.tar + - name: Cleanup tempfile ansible.builtin.file: path: "{{ kubeconfig.path }}" diff --git a/ansible/roles/firstboot/files/ansible_payload/roles/tty/tasks/main.yml b/ansible/roles/firstboot/files/ansible_payload/roles/tty/tasks/main.yml new file mode 100644 index 0000000..e930528 --- /dev/null +++ b/ansible/roles/firstboot/files/ansible_payload/roles/tty/tasks/main.yml @@ -0,0 +1,20 @@ +- name: Create folder structure(s) + ansible.builtin.file: + path: "{{ item }}" + state: directory + loop: + - /opt/firstboot + +- name: Save tty script file + ansible.builtin.template: + src: tty.j2 + dest: /opt/firstboot/tty.sh + user: root + group: root + mode: 0700 + +- name: Create @reboot crontab job + ansible.builtin.cron: + name: tty.consolemessage + special_time: reboot + job: /opt/firstboot/tty.sh diff --git a/ansible/roles/firstboot/files/ansible_payload/templates/tty.j2 b/ansible/roles/firstboot/files/ansible_payload/templates/tty.j2 new file mode 100644 index 0000000..669e636 --- /dev/null +++ b/ansible/roles/firstboot/files/ansible_payload/templates/tty.j2 @@ -0,0 +1,40 @@ +#!/bin/bash + +export TERM=linux + +BGRN='\033[1;92m' +BGRY='\033[1;30m' +BBLU='\033[1;34m' +BRED='\033[1;91m' +BWHI='\033[1;97m' +CBLA='\033[?16;0;30cm' # Hide blinking cursor +DFLT='\033[1;0m' # Reset colour +LCLR='\033[K' # Clear to end of line +PRST='\033[1;92m' # Reset cursor position + +COMPONENTS=('ingress' 'storage' 'registry' 'git' 'gitops') +FQDN='{{ vapp['metacluster.fqdn'] }}' +IPADDRESS='{{ vapp['guestinfo.ipaddres'] }}' + +clear > /dev/tty1 + +while /bin/true; do + echo -e "${PRST}" > /dev/tty1 + echo -e "\n\n\t${DFLT}To manage this appliance, please connect to one of the following:${LCLR}\n" > /dev/tty1 + + for comp in "${COMPONENTS}"; do + STATUS=$(curl -ks "https://${comp}.${FQDN}" -o /dev/null -w '%{http_code}') + + if [[ "${STATUS}" -eq "200" ]]; then + echo -e "\t [${BGRN}+${DFLT}] ${BBLU}https://${comp}.${FQDN}${DFLT}${LCLR}" > /dev/tty1 + else + echo -e "\t [${BRED}-${DFLT}] ${BBLU}https://${comp}.${FQDN}${DFLT}${LCLR}" > /dev/tty1 + fi + done + + echo -e "\n\t${BGRY}Note that your DNS zone ${DFLT}must have ${BGRY} respective records defined, each pointing to:${DFLT}${LCLR}" > /dev/tty1 + echo -e "\t${BGRY} - ${DFLT}${IPADDRESS}${LCLR}" > /dev/tty1 + + echo -e "${CBLA}" > /dev/tty1 + sleep 1 +done diff --git a/ansible/roles/os/tasks/cloud-init.yml b/ansible/roles/os/tasks/cloud-init.yml index ad1f4da..7989472 100644 --- a/ansible/roles/os/tasks/cloud-init.yml +++ b/ansible/roles/os/tasks/cloud-init.yml @@ -3,6 +3,7 @@ name: cloud-init state: absent purge: yes + - name: Delete cloud-init files ansible.builtin.file: path: "{{ item }}" diff --git a/ansible/roles/os/tasks/snapd.yml b/ansible/roles/os/tasks/snapd.yml index fefa5a1..90da33d 100644 --- a/ansible/roles/os/tasks/snapd.yml +++ b/ansible/roles/os/tasks/snapd.yml @@ -3,14 +3,17 @@ name: snapd state: absent purge: yes + - name: Delete leftover files ansible.builtin.file: path: /root/snap state: absent + - name: Hold snapd package ansible.builtin.dpkg_selections: name: snapd selection: hold + - name: Reload systemd unit configurations ansible.builtin.systemd: daemon_reload: yes diff --git a/ansible/roles/os/tasks/tty.yml b/ansible/roles/os/tasks/tty.yml index 7debdc4..acc02c0 100644 --- a/ansible/roles/os/tasks/tty.yml +++ b/ansible/roles/os/tasks/tty.yml @@ -4,8 +4,11 @@ regexp: "{{ item.regexp }}" line: "{{ item.line }}" loop: - - { regexp: '^#NAutoVTs=', line: 'NAutoVTs=1'} - - { regexp: '^#ReserveVT=', line: 'ReserveVT=11'} + - regexp: '^#NAutoVTs=' + line: 'NAutoVTs=1' + - regexp: '^#ReserveVT=' + line: 'ReserveVT=11' + - name: Mask getty@tty1 service ansible.builtin.systemd: name: getty@tty1