Add plays end_metrics.yml and reboot_test3.yml; Add script write_file_msg.py; Update hosts
This commit is contained in:
40
end_metrics.yml
Normal file
40
end_metrics.yml
Normal file
@ -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
|
6
hosts
6
hosts
@ -36,8 +36,10 @@ rear-client ansible_host=10.10.42.192
|
|||||||
ansible_user=root
|
ansible_user=root
|
||||||
|
|
||||||
[temp]
|
[temp]
|
||||||
ipu-test-1 ansible_host=10.10.42.186
|
; debug-stage ansible_host=10.10.42.183
|
||||||
# versionlock-test ansible_host=10.10.42.187
|
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]
|
[temp:vars]
|
||||||
ansible_user=root
|
ansible_user=root
|
||||||
|
41
reboot_test3.yml
Normal file
41
reboot_test3.yml
Normal file
@ -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
|
66
scripts/write_file_msg.py
Executable file
66
scripts/write_file_msg.py
Executable file
@ -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...")
|
Reference in New Issue
Block a user