Updated with proper linting and verifications

This commit is contained in:
p1r9t3 committed 2026-09-16 18:18:41 -07:00
1 parent 3dc6e55e6f
commit ac135ec5a3
12 files changed
+82 -69

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
---
- name: All Servers Test Windows Connectivity And Output Facts
hosts: all
gather_facts: true
tasks:
- name: Ping The Windows Hosts
ansible.windows.win_ping:
- name: Export Facts
ansible.builtin.copy:
mode: "0644"
content: "{{ ansible_facts | to_nice_json }}"
dest: "{{ playbook_dir }}../facts/{{ inventory_hostname }}.json"
delegate_to: localhost
tags: ["never", "debug"]
+35
View File
@@ -0,0 +1,35 @@
---
- name: System maintenance and patching
hosts: ubuntu
become: true
tasks:
- name: Update package cache and upgrade all packages (Ubuntu/Debian)
ansible.builtin.apt:
upgrade: dist
update_cache: true
when: ansible_facts["os_family"] == "Debian"
become: true
- name: Upgrade all packages (RHEL/CentOS/Rocky)
ansible.builtin.dnf:
name: "*"
state: present
when: ansible_facts["os_family"] == "RedHat"
become: true
- name: Check if a reboot is required (Ubuntu/Debian)
ansible.builtin.stat:
path: /var/run/reboot-required
register: reboot_required_file
when: ansible_facts["os_family"] == "Debian"
become: true
- name: Reboot the server if required
ansible.builtin.reboot:
msg: "Reboot initiated by Ansible due to system updates"
connect_timeout: 5
reboot_timeout: 300
when:
- ansible_facts["os_family"] == "Debian"
- reboot_required_file.stat.exists
become: true
+29
View File
@@ -0,0 +1,29 @@
---
- name: Apply Windows Updates
hosts: win_all
gather_facts: true
vars:
initial_reboot: |-
{{ 86400 <
(( ((ansible_date_time.date+" "+ansible_date_time.time)|to_datetime('%Y-%m-%d %H:%M:%S')) -
ansible_facts.lastboot|to_datetime('%Y-%m-%d %H:%M:%SZ')).total_seconds())|abs }}
tasks:
- name: Run Windows Updates
block:
- name: Install Updates And Reboot
ansible.windows.win_updates:
category_names:
- "*"
reboot: false
state: installed
become: true
become_method: ansible.builtin.runas
become_user: SYSTEM
register: update_results
- name: Reboot explicitly if required
ansible.windows.win_reboot:
reboot_timeout: 3600
post_reboot_delay: 120
test_command: 'powershell.exe -Command "Get-Service WinRM"'
when: update_results.reboot_required