From 2530c8c196d9f9651cd182e79ae85c115ad86cb0 Mon Sep 17 00:00:00 2001 From: Chris Hammer Date: Fri, 25 Jul 2025 15:54:25 -0400 Subject: [PATCH] Add plays end_metrics.yml and reboot_test3.yml; Add script write_file_msg.py; Update hosts --- end_metrics.yml | 40 ++++++++++++++++++++++++ hosts | 6 ++-- reboot_test3.yml | 41 ++++++++++++++++++++++++ scripts/write_file_msg.py | 66 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 end_metrics.yml create mode 100644 reboot_test3.yml create mode 100755 scripts/write_file_msg.py diff --git a/end_metrics.yml b/end_metrics.yml new file mode 100644 index 0000000..09a064f --- /dev/null +++ b/end_metrics.yml @@ -0,0 +1,40 @@ +--- +- name: End Metrics + hosts: temp + become: false + gather_facts: true + + tasks: + - name: Execute tasks + when: + - ansible_distribution_major_version == '9' + block: + - name: Loop items + ansible.builtin.debug: + msg: "{{ debug_role }}" + loop: + - 'one' + - 'two' + - 'three' + loop_control: + loop_var: debug_role + + # - name: Flush preupgrade facts + # ansible.builtin.meta: clear_facts + + rescue: + - name: Fail playbook for debug failure + ansible.builtin.debug: + msg: "Debug stage failed, stopping the playbook" + + always: + - name: End metrics for tasks stage + ansible.builtin.set_fact: + debug_metrics: >- + {{ debug_metrics | default({}) | combine({'stages': {'tasks': {'end_time': + now(fmt='%Y%m%d %H:%M:%S')}}}, recursive=True) }} + + + - name: Debug debug_metrics + ansible.builtin.debug: + var: debug_metrics diff --git a/hosts b/hosts index c9d2348..b2e7615 100644 --- a/hosts +++ b/hosts @@ -36,8 +36,10 @@ rear-client ansible_host=10.10.42.192 ansible_user=root [temp] -ipu-test-1 ansible_host=10.10.42.186 -# versionlock-test ansible_host=10.10.42.187 +; debug-stage ansible_host=10.10.42.183 +rear-client ansible_host=10.10.42.192 +; ipu-test-1 ansible_host=10.10.42.186 +; versionlock-test ansible_host=10.10.42.187 [temp:vars] ansible_user=root diff --git a/reboot_test3.yml b/reboot_test3.yml new file mode 100644 index 0000000..302c8a6 --- /dev/null +++ b/reboot_test3.yml @@ -0,0 +1,41 @@ +--- +# -l, --lazy +# Lazy unmount. Detach the filesystem from the file hierarchy now, +# and clean up all references to this filesystem as soon as it +# is not busy anymore. + +# A system reboot would be expected in near future if you’re going to use +# this option for network filesystem or local filesystem with submounts. +# +# The recommended use-case for umount -l is to prevent hangs on shutdown +# due to an unreachable network share where a normal umount will hang +# due to a downed server or a network partition. Remounts of the share +# will not be possible. +- name: Something + hosts: temp + become: true + gather_facts: false + + vars: + __nfs_share: /nfs/backups + + tasks: + - name: Lazily unmount the NFS share + ansible.builtin.command: "umount -f -l {{ __nfs_share }}" + + - name: Reboot host if file changes # noqa: no-handler + ansible.builtin.import_role: + name: verified_reboot + + - name: Unlazily re-mount the file system + ansible.posix.mount: + state: mounted + src: 10.10.42.180:/backups + path: /nfs/backups + opts: rw,noatime + boot: false + fstype: nfs + + +# write script to write files until reboot happens +# script should write number, sleep 1 second, write number, etc diff --git a/scripts/write_file_msg.py b/scripts/write_file_msg.py new file mode 100755 index 0000000..133c427 --- /dev/null +++ b/scripts/write_file_msg.py @@ -0,0 +1,66 @@ +#!/usr/bin/python3 +import time +import os +import readline +from datetime import datetime + +# Changable optonis: +message = "Testing testing testing..." +max_iterations = 5 + + +# Autocomplete path stuffs: +def complete_path(text, state): + expanded = os.path.expanduser(os.path.expandvars(text)) + + if os.path.isdir(expanded): + try: + entries = os.listdir(expanded) + completion_list = [ + os.path.abspath(os.path.join(expanded, entry)) + '/' + if os.path.isdir(os.path.join(expanded, entry)) + else os.path.abspath(os.path.join(expanded, entry)) + for entry in entries + ] + except FileNotFoundError: + completion_list = [] + else: + dirname = os.path.dirname(expanded) + basename = os.path.basename(expanded) + + if not dirname: + dirname = '.' + + try: + entries = [entry for entry in os.listdir(dirname) if entry.startswith(basename)] + completion_list = [ + os.path.abspath(os.path.join(dirname, entry)) + for entry in entries + ] + except FileNotFoundError: + completion_list = [] + + completion_list.sort() + try: + return completion_list[state] + except IndexError: + return None + +readline.set_completer_delims(' \t\n;') +readline.set_completer(complete_path) +readline.parse_and_bind("tab: complete") + +file_path = input("File to write to: ") + +try: + for i in range(max_iterations): + ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + tm = "{} -- {}: itr=>{}".format(ts, message, i) + print(f"{file_path} -> {tm}") + + with open(file_path, "a") as file: + file.write(tm + '\n') + + time.sleep(.2) +except KeyboardInterrupt: + print("Ctrl-C hit; exiting...")