From 66c83a2014bedecac85d2585f6eac31e801f946e Mon Sep 17 00:00:00 2001 From: abrown38 Date: Fri, 23 May 2025 11:26:44 +0100 Subject: [PATCH] update stuff --- ansible/roles/win_client/tasks/main.yml | 1 - ansible/roles/win_client/tasks/start_menu.yml | 18 ++++ ansible/roles/win_client/tasks/update.yml | 59 ------------ ansible/roles/win_client/vars/main.yml | 4 +- ansible/roles/win_update/tasks/update.yml | 93 ++++++++++--------- ansible/roles/win_update/vars/main.yml | 4 +- ansible/roles/win_wsus/tasks/configure.yml | 2 +- 7 files changed, 72 insertions(+), 109 deletions(-) delete mode 100644 ansible/roles/win_client/tasks/update.yml diff --git a/ansible/roles/win_client/tasks/main.yml b/ansible/roles/win_client/tasks/main.yml index abca8ee..2ba3891 100644 --- a/ansible/roles/win_client/tasks/main.yml +++ b/ansible/roles/win_client/tasks/main.yml @@ -3,4 +3,3 @@ - import_tasks: chocolatey.yml - import_tasks: rdgw.yml - import_tasks: start_menu.yml -- import_tasks: update.yml diff --git a/ansible/roles/win_client/tasks/start_menu.yml b/ansible/roles/win_client/tasks/start_menu.yml index 7dfd098..2e790a5 100644 --- a/ansible/roles/win_client/tasks/start_menu.yml +++ b/ansible/roles/win_client/tasks/start_menu.yml @@ -38,6 +38,24 @@ when: inventory_hostname in groups['meta-variant_gpu'] when: groups['meta-variant_gpu'] is defined +- name: Update Start Menu Shortcutsm + tags: update_start_menu + block: + - name: Copy Python script to target machine + ansible.windows.win_template: + src: '{{ script_name }}' + dest: '{{ script_path }}' + force: true + + - name: Copy current XML to backup location + win_copy: + remote_src: true + src: '{{ start_menu_xml }}' + dest: '{{ backup_xml }}' + + - name: Run Python script on remote machine + win_command: python "{{ script_path }}" + - name: Update Group Policy win_shell: gpupdate /force /boot /logoff tags: diff --git a/ansible/roles/win_client/tasks/update.yml b/ansible/roles/win_client/tasks/update.yml deleted file mode 100644 index bcfd65b..0000000 --- a/ansible/roles/win_client/tasks/update.yml +++ /dev/null @@ -1,59 +0,0 @@ ---- -- name: Install all updates and reboot as many times as needed - tags: update_windows - block: - - name: Install Windows updates (looped) - ansible.windows.win_updates: - category_names: '*' - reboot: true - register: update_result - retries: 5 - delay: 30 - until: update_result.reboot_required == false - - - name: Wait for host to come back online - ansible.builtin.wait_for_connection: - timeout: 600 - -- name: Install all Windows updates and reboot if required - tags: update_windows1 - block: - - name: Install Windows updates (no auto reboot) - ansible.windows.win_updates: - category_names: '*' - reboot: false - register: update_result - - - name: Reboot the machine if updates require it - ansible.windows.win_reboot: - when: update_result.reboot_required - - - name: Wait for the host to come back online - ansible.builtin.wait_for_connection: - timeout: 600 -- name: Update all choco packages - win_command: choco upgrade all -y - tags: update_choco - -- name: Update Start Menu Shortcuts in XML on remote Windows machines - tags: update_start_menu - block: - - name: Copy Python script to target machine - ansible.windows.win_template: - src: "{{ script_name }}" - dest: "{{ script_path }}" - force: true - - - name: Copy current XML to backup location - win_copy: - remote_src: true - src: "{{ start_menu_xml }}" - dest: "{{ backup_xml }}" - - - name: Run Python script on remote machine - win_command: python "{{ script_path }}" - register: output - - - name: debug - debug: - var: output diff --git a/ansible/roles/win_client/vars/main.yml b/ansible/roles/win_client/vars/main.yml index 8f452d0..b0b83ac 100644 --- a/ansible/roles/win_client/vars/main.yml +++ b/ansible/roles/win_client/vars/main.yml @@ -1,5 +1,5 @@ repo_url: 'http://{{ win_project }}-choc.{{ win_project }}.loc/chocolatey' -start_menu_xml: "C:\\\\eidf\\\\{{ win_project }}.xml" -backup_xml: "C:\\\\eidf\\\\{{ win_project }}-old.xml" +start_menu_xml: "C:\\eidf\\{{ win_project }}.xml" +backup_xml: "C:\\eidf\\{{ win_project }}-old.xml" script_name: newXML.py script_path: "C:\\eidf\\{{ script_name }}" diff --git a/ansible/roles/win_update/tasks/update.yml b/ansible/roles/win_update/tasks/update.yml index bfeda45..bf74567 100644 --- a/ansible/roles/win_update/tasks/update.yml +++ b/ansible/roles/win_update/tasks/update.yml @@ -1,14 +1,10 @@ --- -- name: Install client VM updates and reboot as much as needed +- name: Install all updates and reboot as many times as needed + tags: update_windows1 block: - name: Install Windows updates (looped) - tags: update_windows ansible.windows.win_updates: - category_names: - - CriticalUpdates - - DefinitionUpdates - - SecurityUpdates - - UpdateRollups + category_names: '*' reboot: true register: update_result retries: 5 @@ -16,50 +12,59 @@ until: update_result.reboot_required == false - name: Wait for host to come back online - tags: update_windows ansible.builtin.wait_for_connection: timeout: 600 - - name: Update all choco packages - win_command: choco upgrade all -y - tags: update_choco - - - name: Update Start Menu Shortcuts in XML on remote Windows machines - tags: update_start_menu - block: - - name: Copy Python script to target machine - ansible.windows.win_template: - src: "{{ script_name }}" - dest: "{{ script_path }}" - force: true - - - name: Copy current XML to backup location - win_copy: - remote_src: true - src: "{{ start_menu_xml }}" - dest: "{{ backup_xml }}" - - - name: Run Python script on remote machine - win_command: python "{{ script_path }}.xml" - when: "inventory_hostname in groups['meta-type_client']|default([])" - -- name: Install Server VM updates and reboot as much as needed +- name: Install all Windows updates and reboot if required tags: update_windows block: - - name: Install Windows updates (looped) + - name: Install Windows updates (no auto reboot) ansible.windows.win_updates: - category_names: - - CriticalUpdates - - DefinitionUpdates - - SecurityUpdates - - UpdateRollups - reboot: true + category_names: '*' + reboot: false register: update_result - retries: 5 - delay: 30 - until: update_result.reboot_required == false - - name: Wait for host to come back online + - name: Reboot the machine if updates require it + ansible.windows.win_reboot: + when: update_result.reboot_required + + - name: Wait for the host to come back online ansible.builtin.wait_for_connection: timeout: 600 - when: "inventory_hostname in groups['meta-type_server']" + +- name: Update all choco packages + tags: update_choco + block: + - name: Run Chocolatey upgrade (allow failure, don't mark as failed) + win_command: choco upgrade all -y --ignore-checksums --failonunfound --continue-on-failure + register: choco_result + ignore_errors: true + failed_when: false # << This prevents Ansible from treating it as a failed task + + - name: Show Chocolatey output + debug: + var: choco_result + +- name: Update Start Menu Shortcuts in XML on remote Windows machines + tags: update_start_menu + block: + - name: Copy Python script to target machine + ansible.windows.win_template: + src: "{{ script_name }}" + dest: "{{ script_path }}" + force: true + + - name: Copy current XML to backup location + win_copy: + remote_src: true + src: "{{ start_menu_xml }}" + dest: "{{ backup_xml }}" + + - name: Run Python script on remote machine + win_command: python "{{ script_path }}" + register: output + + - name: debug + debug: + var: output + diff --git a/ansible/roles/win_update/vars/main.yml b/ansible/roles/win_update/vars/main.yml index aba6bed..86e8fc1 100644 --- a/ansible/roles/win_update/vars/main.yml +++ b/ansible/roles/win_update/vars/main.yml @@ -1,5 +1,5 @@ --- -start_menu_xml: "C:\\eidf\\{{ win_project }}.xml" -backup_xml: "C:\\eidf\\{{ win_project }}-old.xml" +start_menu_xml: "C:\\\\eidf\\\\{{ win_project }}.xml" +backup_xml: "C:\\\\eidf\\\\{{ win_project }}-old.xml" script_name: newXML.py script_path: "C:\\eidf\\{{ script_name }}" \ No newline at end of file diff --git a/ansible/roles/win_wsus/tasks/configure.yml b/ansible/roles/win_wsus/tasks/configure.yml index 0baa670..82f46a9 100644 --- a/ansible/roles/win_wsus/tasks/configure.yml +++ b/ansible/roles/win_wsus/tasks/configure.yml @@ -20,7 +20,7 @@ tags: copy_wsus_optimization_script - name: Apply WSUS script - win_shell: "powershell {{ script_dir }}\\{{ wsus_script }}" + win_shell: "powershell -windowstyle hidden -file \"{{ script_dir }}\\{{ wsus_script }}\"" tags: - apply_wsus_script - never