Skip to content
Snippets Groups Projects

playbook-reboot-is-update-is-more-x-days.yml

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by RDR-IT
    playbook-reboot-is-update-is-more-x-days.yml 877 B
    ---
      - name: Reboot if uptime more 13 days
        hosts: all
    
        tasks:
          - name: Get uptime in PowerShell And Reboot if need
            ansible.windows.win_shell: |
                $uptime = (get-date) - (gcim Win32_OperatingSystem).LastBootUpTime
                $uptimeJson = $uptime | ConvertTo-Json
                Write-Output $uptimeJson
            register: resultps
          
          - name: Process output
            set_fact:
              uptime: "{{ resultps.stdout  | from_json }}"
    
          - name: Show Uptime
            debug:
              msg: Uptime is {{ uptime.Days }}
          
          - name: Need Reboot Debug
            debug:
              msg: Computer need reboot
            when: (uptime.Days > 13)
          
          - name: Reboot computer
            ansible.windows.win_reboot:
              msg: Reboot by ansible because uptime is more 13 days
              reboot_timeout: 600
            when: (uptime.Days > 13)
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment