From 5329efdffa958363e734b09be06dae39b5a52085 Mon Sep 17 00:00:00 2001 From: cfinlay Date: Mon, 22 Jul 2024 14:09:40 +0100 Subject: [PATCH] Portal roles --- ansible/playbooks/reboot.yml | 10 +++++++++ ansible/playbooks/update.yml | 9 ++++++++ ansible/roles/reboot/tasks/main.yml | 2 ++ ansible/roles/reboot/tasks/reboot.yml | 29 +++++++++++++++++++++++++ ansible/roles/update/meta/main.yml | 2 ++ ansible/roles/update/tasks/main.yml | 2 ++ ansible/roles/update/tasks/update.yml | 31 +++++++++++++++++++++++++++ ansible/roles/update/vars/main.yml | 6 ++++++ 8 files changed, 91 insertions(+) create mode 100644 ansible/playbooks/reboot.yml create mode 100644 ansible/playbooks/update.yml create mode 100644 ansible/roles/reboot/tasks/main.yml create mode 100644 ansible/roles/reboot/tasks/reboot.yml create mode 100644 ansible/roles/update/meta/main.yml create mode 100644 ansible/roles/update/tasks/main.yml create mode 100644 ansible/roles/update/tasks/update.yml create mode 100644 ansible/roles/update/vars/main.yml diff --git a/ansible/playbooks/reboot.yml b/ansible/playbooks/reboot.yml new file mode 100644 index 0000000..30349aa --- /dev/null +++ b/ansible/playbooks/reboot.yml @@ -0,0 +1,10 @@ +--- +- name: Reboot VMs and log time + hosts: "{{ target_host }}" + gather_facts: true + roles: + - reboot + vars_files: + - ../vars/vars.yml + - ../vars/connection.yml + - ../vars/common.yml diff --git a/ansible/playbooks/update.yml b/ansible/playbooks/update.yml new file mode 100644 index 0000000..09ac5d2 --- /dev/null +++ b/ansible/playbooks/update.yml @@ -0,0 +1,9 @@ +- name: Running Update Playbook + hosts: '{{ target_host }}' + gather_facts: true + roles: + - update + vars_files: + - ../vars/vars.yml + - ../vars/connection.yml + - ../vars/common.yml diff --git a/ansible/roles/reboot/tasks/main.yml b/ansible/roles/reboot/tasks/main.yml new file mode 100644 index 0000000..97fcaca --- /dev/null +++ b/ansible/roles/reboot/tasks/main.yml @@ -0,0 +1,2 @@ +- name: Running reboot roles + include_tasks: reboot.yml diff --git a/ansible/roles/reboot/tasks/reboot.yml b/ansible/roles/reboot/tasks/reboot.yml new file mode 100644 index 0000000..1083e2e --- /dev/null +++ b/ansible/roles/reboot/tasks/reboot.yml @@ -0,0 +1,29 @@ +--- +- name: Rebooting hosts + ansible.windows.win_reboot: + msg: "rebooting VM, initiated by ansible" + reboot_timeout: 3600 + register: status + +- 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 diff --git a/ansible/roles/update/meta/main.yml b/ansible/roles/update/meta/main.yml new file mode 100644 index 0000000..23d65c7 --- /dev/null +++ b/ansible/roles/update/meta/main.yml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/ansible/roles/update/tasks/main.yml b/ansible/roles/update/tasks/main.yml new file mode 100644 index 0000000..61d6e2e --- /dev/null +++ b/ansible/roles/update/tasks/main.yml @@ -0,0 +1,2 @@ +- name: Running Update playbook + include_tasks: update.yml diff --git a/ansible/roles/update/tasks/update.yml b/ansible/roles/update/tasks/update.yml new file mode 100644 index 0000000..7340eb4 --- /dev/null +++ b/ansible/roles/update/tasks/update.yml @@ -0,0 +1,31 @@ +--- +- 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 (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 diff --git a/ansible/roles/update/vars/main.yml b/ansible/roles/update/vars/main.yml new file mode 100644 index 0000000..47f4512 --- /dev/null +++ b/ansible/roles/update/vars/main.yml @@ -0,0 +1,6 @@ +--- +services: + - wuauserv + - bits + - cryptSvc + - msiserver