mirror of
https://git.ecdf.ed.ac.uk/win_automation/windows-ansible.git
synced 2026-10-30 09:36:51 +00:00
win_update changes
This commit is contained in:
1 parent
66c83a2014
commit
74b5c802a2
5 files changed
+44
-65
No files matched your search
@@ -43,18 +43,18 @@
|
|||||||
block:
|
block:
|
||||||
- name: Copy Python script to target machine
|
- name: Copy Python script to target machine
|
||||||
ansible.windows.win_template:
|
ansible.windows.win_template:
|
||||||
src: '{{ script_name }}'
|
src: "{{ script_name }}"
|
||||||
dest: '{{ script_path }}'
|
dest: "{{ script_path }}"
|
||||||
force: true
|
force: true
|
||||||
|
|
||||||
- name: Copy current XML to backup location
|
- name: Copy current XML to backup location
|
||||||
win_copy:
|
win_copy:
|
||||||
remote_src: true
|
remote_src: true
|
||||||
src: '{{ start_menu_xml }}'
|
src: "{{ start_menu_xml }}"
|
||||||
dest: '{{ backup_xml }}'
|
dest: "{{ backup_xml }}"
|
||||||
|
|
||||||
- name: Run Python script on remote machine
|
- name: Run Python script on remote machine
|
||||||
win_command: python "{{ script_path }}"
|
win_command: python {{ script_path }}
|
||||||
|
|
||||||
- name: Update Group Policy
|
- name: Update Group Policy
|
||||||
win_shell: gpupdate /force /boot /logoff
|
win_shell: gpupdate /force /boot /logoff
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import shutil
|
|||||||
import re
|
import re
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
original_xml = "{{ start_menu_xml }}"
|
original_xml = r"{{ start_menu_xml }}"
|
||||||
backup_xml = "{{ backup_xml }}"
|
backup_xml = r"{{ backup_xml }}"
|
||||||
|
|
||||||
# This script assumes backup and copying already handled by Ansible
|
# This script assumes backup and copying already handled by Ansible
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
---
|
---
|
||||||
- import_tasks: update.yml
|
- import_tasks: update.yml
|
||||||
|
- import_tasks: software.yml
|
||||||
|
when: "inventory_hostname in groups['meta-type_client']|default([])"
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
---
|
||||||
|
- name: Update all choco packages
|
||||||
|
tags: update_choco
|
||||||
|
block:
|
||||||
|
- name: Run Chocolatey upgrade (allow failure, don't mark as failed)
|
||||||
|
win_shell: |
|
||||||
|
choco upgrade all -y --ignore-checksums --failonunfound --continue-on-failure
|
||||||
|
register: choco_result
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- 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 current XML to backup location
|
||||||
|
win_copy:
|
||||||
|
remote_src: true
|
||||||
|
src: "{{ start_menu_xml }}"
|
||||||
|
dest: "{{ backup_xml }}"
|
||||||
|
force: true
|
||||||
|
|
||||||
|
- name: Run Python script on remote machine
|
||||||
|
win_command: python {{ script_path }}
|
||||||
|
|
||||||
|
rescue:
|
||||||
|
- name: Restore backup XML
|
||||||
|
win_copy:
|
||||||
|
remote_src: true
|
||||||
|
src: "{{ backup_xml }}"
|
||||||
|
dest: "{{ start_menu_xml }}"
|
||||||
|
force: true
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
- name: Install all updates and reboot as many times as needed
|
- name: Install all updates and reboot as many times as needed
|
||||||
tags: update_windows1
|
tags: update_windows
|
||||||
block:
|
block:
|
||||||
- name: Install Windows updates (looped)
|
- name: Install Windows updates (looped)
|
||||||
ansible.windows.win_updates:
|
ansible.windows.win_updates:
|
||||||
@@ -11,60 +11,3 @@
|
|||||||
delay: 30
|
delay: 30
|
||||||
until: update_result.reboot_required == false
|
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_windows
|
|
||||||
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
|
|
||||||
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
|
|
||||||
|
|
||||||
Reference in new issue
Block a user