From a86a6ba9643ca935d5df8f8e891140694ece86f9 Mon Sep 17 00:00:00 2001 From: abrown38 Date: Mon, 22 Jul 2024 14:22:18 +0100 Subject: [PATCH] use ansible blocks with tags, also use standard layout --- ansible/roles/win_reboot/tasks/reboot.yml | 40 ++++++----------- ansible/roles/win_update/tasks/update.yml | 53 +++++++++++------------ 2 files changed, 39 insertions(+), 54 deletions(-) diff --git a/ansible/roles/win_reboot/tasks/reboot.yml b/ansible/roles/win_reboot/tasks/reboot.yml index 1083e2e..437c439 100644 --- a/ansible/roles/win_reboot/tasks/reboot.yml +++ b/ansible/roles/win_reboot/tasks/reboot.yml @@ -1,29 +1,15 @@ --- -- name: Rebooting hosts - ansible.windows.win_reboot: - msg: "rebooting VM, initiated by ansible" - reboot_timeout: 3600 - register: status +- name: Reboot VM + tags: reboot_vm + block: + - name: Rebooting hosts + ansible.windows.win_reboot: + msg: "rebooting VM, initiated by ansible" + reboot_timeout: 3600 -- name: Delay WinRM - ansible.windows.win_service: - name: WinRM - start_mode: delayed - - #- name: Force Openstack Reboot - # openstack.cloud.server_action: - # action: "reboot_hard" - #name: "{{ ansible_hostname }}" - # when: not status | bool - - #- name: Delay WinRM - # ansible.windows.win_service: - # name: WinRM - # start_mode: delayed - -- name: Logging action - vars: - ansible_connection: local - ansible.builtin.shell: - cmd: echo "Reboot {{ os_project }}-{{ ansible_hostname }} $(date '+%Y-%m-%d %H:%M:%S')" >> /deployments/{{ os_project }}-{{ win_project }}/action.log - delegate_to: localhost + - name: Logging action + vars: + ansible_connection: local + ansible.builtin.shell: + cmd: echo "Reboot {{ os_project }}-{{ ansible_hostname }} $(date '+%Y-%m-%d %H:%M:%S')" >> /deployments/{{ os_project }}-{{ win_project }}/action.log + delegate_to: localhost diff --git a/ansible/roles/win_update/tasks/update.yml b/ansible/roles/win_update/tasks/update.yml index 7340eb4..0a502a6 100644 --- a/ansible/roles/win_update/tasks/update.yml +++ b/ansible/roles/win_update/tasks/update.yml @@ -1,31 +1,30 @@ --- -- name: Clear update cache - win_shell: | - UsoClient RefreshSettings - UsoClient ScanInstallWait +- name: Update VM + tags: update_vm + block: + - name: Clear update cache + win_shell: | + UsoClient RefreshSettings + UsoClient ScanInstallWait -- name: Update Windows - ansible.windows.win_updates: - category_names: '*' - skip_optional: true - reboot: true - reboot_timeout: 3600 - vars: - ansible_become: true - ansible_become_pass: "{{ ansible_password }}" - ansible_become_user: Administrator - ignore_errors: true + - name: Update Windows + ansible.windows.win_updates: + category_names: '*' + skip_optional: true + reboot: true + reboot_timeout: 3600 + ignore_errors: true -- name: Update Windows (again) - ansible.windows.win_updates: - category_names: '*' - reboot: true - reboot_timeout: 3600 - ignore_errors: true + - name: Update Windows (again) + ansible.windows.win_updates: + category_names: '*' + reboot: true + reboot_timeout: 3600 + ignore_errors: true -- name: Logging action - vars: - ansible_connection: local - ansible.builtin.shell: - cmd: echo "Update {{ os_project }}-{{ ansible_hostname }} $(date '+%Y-%m-%d %H:%M:%S')" >> /deployments/{{ os_project }}-{{ win_project }}/action.log - delegate_to: localhost + - name: Logging action + vars: + ansible_connection: local + ansible.builtin.shell: + cmd: echo "Update {{ os_project }}-{{ ansible_hostname }} $(date '+%Y-%m-%d %H:%M:%S')" >> /deployments/{{ os_project }}-{{ win_project }}/action.log + delegate_to: localhost