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.
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
Once you have downloaded the repository, you have to configure some parameters so the framework is able to connect to the environment.
The credential store contains the passwords to connect to your linux and windows systems.
Setup your vault using the following procedure:
- Save vault password to file
echo MyPassword > vault-password.txt
- create ansible vault
# create vault
ansible-vault create ./environments/prod/group_vars/all/vault.yml
- enter the following information
# Connection parameters
windows_admin_username: "myDomain\\myWindowsUser"
windows_admin_password: "myWindowsPassword"
linux_admin_username: "myLinuxUser"
linux_admin_password: "myLinuxPassword"
- edit hosts file
edit the host file as desired
vi ./environments/prod/hosts
If you plan to use the 'prtg' module you have to setup the following
- add prtg parameters to your vault
ansible-vault edit ./environments/prod/group_vars/all/vault.yml
- 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
- 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.
The password hash has to be taken from PRTG.
If you plan to use the 'hyperv' module you have to setup the following:
- add hyperv parameters to your vault
ansible-vault edit ./environments/prod/group_vars/all/vault.yml
- append your prtg connection parameters
# parameters for module 'hyperv'
module_hyperv_host: 172.20.0.91
- 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
This section contains some examples of playbooks that show the usage of the custom modules in the repository.
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.
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
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
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
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.
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
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
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
This repository contains custom modules for ansible so you are able to connect to 3rd party systems, run checks and actions.
Modules for Paessler PRTG monitoring.
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)
library/action_plugins/pause_prtg
Custom module that can be used to pause or resume monitoring of a device in prtg.
- Module should be executed on a linux system that has connectivity (http) to the prtg server.
- For Example Usage see playbook pause-monitoring.yml
- For Example Usage see playbook resume-monitoring.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 after the action is taken (i.e. "paused", "running"). Default: "paused"
Modules for checking-, creating- and deleting snapshots on Microsoft Hyper-V Hypervisors.
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
library/action_plugins/hyperv_action_createsnapshot
Custom module that can be used to create a new snapshot for a hyper-v vm
- Module is a powershell script should be executed on a windows hyper-v host
- For Example Usage see playbook hyperv-action-createsnapshot.yml
Parameters
- vmname:
name of hyper-v vm where snapshot should be created (i.e. "myvm01") - snapshotName:
(optional) name of snapshot that should be created
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"