Skip to content

butschi84/ansible-server-patching

Repository files navigation

ansible - server patching framework

⚠️ Use at your own risk ⚠️

This repository will contain ansible playbooks and custom modules helpful to patch windows and linux systems. You will also be able to run checks and actions on third party systems like prtg, hyper-v, veeam and so on.

Features

These are the current Features of the patching framework.

  • Hyper-V
    • Start a VM
    • Stop a VM
    • Check if a VM has a snapshot younger than x-Minutes
    • Check if a VM has no snapshots
    • Create a snapshot for a VM
  • PRTG
    • Pause monitoring of a PRTG Device
    • Resume monitoring of a PRTG Device
    • Check current monitoring status of a PRTG Device

Contents

Setup Framework

Once you have downloaded the repository, you have to configure some parameters so the framework is able to connect to the environment.

Setup credentials

The credential store contains the passwords to connect to your linux and windows systems.

Setup your vault using the following procedure:

  1. Save vault password to file
echo MyPassword > vault-password.txt
  1. create ansible vault
# create vault
ansible-vault create ./environments/prod/group_vars/all/vault.yml
  1. enter the following information
# Connection parameters
windows_admin_username: "myDomain\\myWindowsUser"
windows_admin_password: "myWindowsPassword"
linux_admin_username: "myLinuxUser"
linux_admin_password: "myLinuxPassword"
  1. edit hosts file

edit the host file as desired

vi ./environments/prod/hosts

Module - PRTG

If you plan to use the 'prtg' module you have to setup the following

  1. add prtg parameters to your vault
ansible-vault edit ./environments/prod/group_vars/all/vault.yml
  1. append your prtg connection parameters
# parameters for module 'prtg'
module_prtg_server_address: 172.20.0.91
module_prtg_api_username: exampleUser
module_prtg_api_passhash: 111111111
  1. edit environments/prod/group_vars/all/hosts

Add the prtg_device_id to each of the hosts you want to use with the prtg module like so:

[windows_servers]
example_server ansible_host=172.20.0.91 prtg_device_id=1027

You can find the PRTG device id in your prtg web interface.

prtg readyness

The password hash has to be taken from PRTG.

Module - HYPERV

If you plan to use the 'hyperv' module you have to setup the following:

  1. add hyperv parameters to your vault
ansible-vault edit ./environments/prod/group_vars/all/vault.yml
  1. append your prtg connection parameters
# parameters for module 'hyperv'
module_hyperv_host: 172.20.0.91
  1. edit environments/prod/group_vars/all/hosts

Add the hyperv_vmname to each of the hosts you want to use with the hyperv module like so:

[windows_servers]
exampleServerVM ansible_host=172.20.0.91 hyperv_vmname=exampleServerVM

Playbooks

This section contains some examples of playbooks that show the usage of the custom modules in the repository.

PRTG

Playbooks useful to run checks on you PRTG monitoring, pause sensors, resume sensors.

These playbooks use the 'prtg' module of this repository. So make sure you have setup the prtg module correctly as specified in the 'Setup Framework' section.

check-readyness.yml

playbooks/prtg/check-readyness.yml

Example Playbook to check the current status of a device / system in prtg. Each host will be checked in prtg by using its specific device id.

# Usage:
ansible-playbook playbooks/prtg/check-readyness.yml --limit example_server

pause-monitoring.yml

playbooks/prtg/pause-monitoring.yml

Example Playbook to pause monitoring of a device / system in prtg.

# Usage:
ansible-playbook playbooks/prtg/pause-monitoring.yml --limit example_server

resume-monitoring.yml

playbooks/prtg/resume-monitoring.yml

Example Playbook to resume monitoring of a device / system in prtg.

# Usage:
ansible-playbook playbooks/prtg/resume-monitoring.yml --limit example_server

Hyper-V

Playbooks useful to run checks on your Hyper-V Host, check snapshots and age, create snapshots, delete snapshots.

These playbooks use the 'hyperv' module of this repository. So make sure you have setup the hyperv module correctly as specified in the 'Setup Framework' section.

hyperv-check-snapshots.yml

playbooks/hyperv/hyperv-check-snapshots.yml

Example Playbook to check wether a hyper-v vm has a snapshot and age is younger than 1 day.

# Usage:
ansible-playbook playbooks/hyperv/hyperv-check-snapshots.yml --limit example_server

hyperv-action-createsnapshot.yml

playbooks/hyperv/hyperv-action-createsnapshot.yml

Example Playbook to show snapshot creation for a hyper-v vm.

# Usage:
ansible-playbook playbooks/hyperv/hyperv-action-createsnapshot.yml --limit example_server

hyperv-check-nosnapshots.yml

playbooks/hyperv/hyperv-check-nosnapshots.yml

Example Playbook to check wether a hyper-v vm has no snapshot.

# Usage:
ansible-playbook playbooks/hyperv/hyperv-check-nosnapshots.yml --limit example_server

Custom Modules

This repository contains custom modules for ansible so you are able to connect to 3rd party systems, run checks and actions.

PRTG

Modules for Paessler PRTG monitoring.

check_prtg

library/action_plugins/check_prtg

Custom module that can be used to check the status of a device in prtg monitoring (up, warning, down).

  • Module should be executed on a linux system that has connectivity (http) to the prtg server.
  • For Example Usage see playbook check-readyness.yml

Parameters

  • api_user: PRTG user for making API calls (can be local or domain user i.e. "prtgadmin")
  • api_passhash: Passhash from PRTG for API access (i.e. 1234512345)
  • prtg_url: Address of PRTG Server (i.e. "192.168.2.100")
  • device_id: Id of device in PRTG that should be checked (i.e. "1022")
  • status: Desired Status of device in PRTG (i.e. "up", "warning", "down"). Default: "up"
  • waitFor: If device does not have the desired status in PRTG, how many seconds should we wait (default: 0)

pause_prtg

library/action_plugins/pause_prtg

Custom module that can be used to pause or resume monitoring of a device in prtg.

Parameters

  • api_user: PRTG user for making API calls (can be local or domain user i.e. "prtgadmin")
  • api_passhash: Passhash from PRTG for API access (i.e. 1234512345)
  • prtg_url: Address of PRTG Server (i.e. "192.168.2.100")
  • device_id: Id of device in PRTG that should be checked (i.e. "1022")
  • status: Desired Status of device in PRTG after the action is taken (i.e. "paused", "running"). Default: "paused"

Hyper-V

Modules for checking-, creating- and deleting snapshots on Microsoft Hyper-V Hypervisors.

hyperv_check_snapshots

library/action_plugins/hyperv_check_snapshots

Custom module that can be used to check wether a hyper-v vm has a snapshot and also age of the snapshot.

  • Module is a powershell script should be executed on a windows hyper-v host
  • For Example Usage see playbook hyperv-check-snapshots.yml

Parameters

  • vmname:
    name of hyper-v vm that should be checked (i.e. "myvm01")
  • state:
    state of snapshot should be: "absent" or "present"
  • snapshotAgeYoungerThanMinutes:
    max snapshot age in minutes if "present" was specified

hyperv_action_createsnapshot

library/action_plugins/hyperv_action_createsnapshot

Custom module that can be used to create a new snapshot for a hyper-v vm

Parameters

  • vmname:
    name of hyper-v vm where snapshot should be created (i.e. "myvm01")
  • snapshotName:
    (optional) name of snapshot that should be created

hyperv_action_state

library/action_plugins/hyperv_action_state

Custom module that can be used to start or shutdown a hyper-v vm.

  • Module is a powershell script should be executed on a windows hyper-v host

Parameters

  • vmname:
    name of hyper-v vm that should be started or shutdown (i.e. "myvm01")
  • state:
    state of vm should be: "running" or "stopped"

About

A framework of ansible playbooks and modules useful for linux- and windows-server patching

Resources

Stars

Watchers

Forks

Packages

No packages published