VeeamHub / veeam-ansible

Sample code for deploying and configuring various Veeam solutions using Ansible.
GNU Lesser General Public License v3.0
48 stars 20 forks source link

Add Auto Reboot var #56

Open mritsurgeon opened 10 months ago

mritsurgeon commented 10 months ago

install_VBR.yml

- name: Checking OS for pending reboots
  block:
    - name: "Check for pending reboots"
      pending_reboot_check:
      register: precheck
      failed_when: "(precheck.pending_reboot | bool) and (auto_reboot == 'no')"

- name: Handle pending reboots and initiate reboot if necessary
  block:
    - name: "Reboot if necessary"
      ansible.windows.win_reboot:
        test_command: 'exit (Get-Service -Name Netlogon).Status -eq "Running"'
      retries: 5
      delay: 60
      until: 'test_command_result.rc == 0'
  when: precheck | bool

- name: Display message if pending reboot
  debug:
    msg: "Pending reboot, Auto reboot set to no"
  when: precheck.pending_reboot | bool and auto_reboot == 'no'

Example Playbook :

- name: Veeam Backup & Replication Install
  hosts: vbr
  tasks:
    - include_role:
        name: veeamhub.veeam.veeam_vas
        tasks_from: vbr_install
      vars:
        version: "12"
        auto_reboot: "yes"
        sql_install_username: 'sql_install'
        sql_install_password: 'windows_password'
        sql_service_username: 'svc_sql'
        sql_service_password: 'windows_password'
        sql_username: 'postgres'
        sql_password: 'linux_password'
carceneaux commented 9 months ago

Thanks for the suggestion!

Can you please elaborate on how this would be beneficial for your use case?

mritsurgeon commented 9 months ago

Automatically rebooting server then waiting for it to be available and then starting with next task , all controlled via one playbook run , as the example I shared which I modified to use , I’m running a UI that’s calling playbook in backend & passing variables , without auto reboot I’ll have to code a reboot button in UI. Simple Boolean Syntax can be passed to playbook through a tick box.

If a server needs reboot now you need to manually reboot it & the rerun playbook, what I suggested and sample is playbook initiates reboot then waits then continues.

carceneaux commented 9 months ago

Thanks for the additional info.

So in most places in this collection a reboot already occurs when needed. The only exception to that is in the pre-checks.

I left this at a fail as I expected the user to code to check for a pending reboot before initiating an install/upgrade to their Veeam environment. I was hesitant to include an automatic reboot here at the beginning in case jobs are still running or there is some other unforeseen environment change. For example, if someone had neglected to reboot after Windows updates, the reboot could take quite some time.

For the time being, I recommend checking for a pending reboot prior to executing a Veeam install/upgrade.