additional tasks for VM creation

This commit is contained in:
2025-07-08 09:59:41 -05:00
parent 3d4afce244
commit 2bce9c3f29
41 changed files with 23849 additions and 921 deletions

View File

@@ -11,19 +11,24 @@ brew tap hashicorp/tap
brew install hashicorp/tap/packer brew install hashicorp/tap/packer
``` ```
packer plugins install github.com/hashicorp/proxmox fedora-<version>/
packer plugins install github.com/hashicorp/ansible ├── fedora-<version>.pkr.hcl # Main build definition(s)
my-packer-project/
├── main.pkr.hcl # Main build definition(s)
├── variables.pkr.hcl # Variable declarations and default values ├── variables.pkr.hcl # Variable declarations and default values
├── <image_name>.pkrvars.hcl # (Optional) Specific variable values for a particular image ├── <image_name>.pkrvars.hcl # (Optional) Specific variable values for a particular image
├── scripts/ # Directory for shell/PowerShell scripts used by provisioners ├── files/ # Files to load on VM
── setup-apache.sh ── ansible.pub # public key for ansible user
│ ├── install-deps.ps1 ├── scripts/ # Directory for shell scripts
── common-config.sh ── cleanup.sh # Clean up the template
├── httpd-template/ # (Optional) Subdirectory for a specific image's configuration │ └── setup.yml # Ansible playbook
│ ├── source.pkr.hcl # Source block for Apache image ├── httpd/ # Subdirectory for kickstart configiration
── build.pkr.hcl # Build block for Apache image ── ks.cfg # Source block for Apache image
│ └── vars.pkrvars.hcl # Variables specific to Apache image
└── README.md └── README.md
# Create templates
```bash
packer build -var-file ./fedora-42-small.pkrvars.hcl -var-file ./proxmox.pkvars.hcl -var 'ssh_password=<wed ssh password>' -var 'proxmox_password=<proxmox user password>' .
packer build -var-file ./fedora-42-medium.pkrvars.hcl -var-file ./proxmox.pkvars.hcl -var 'ssh_password=<wed ssh password>' -var 'proxmox_password=<proxmox user password>' .
packer build -var-file ./fedora-42-large.pkrvars.hcl -var-file ./proxmox.pkvars.hcl -var 'ssh_password=<wed ssh password>' -var 'proxmox_password=<proxmox user password>' .
packer build -var-file ./fedora-42-xlarge.pkrvars.hcl -var-file ./proxmox.pkvars.hcl -var 'ssh_password=<wed ssh password>' -var 'proxmox_password=<proxmox user password>' .
```

View File

@@ -1,21 +0,0 @@
MIT License
Copyright (c) 2019 eaksel
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,63 +0,0 @@
# packer-CentOS8
## What is packer-CentOS8 ?
packer-CentOS8 is a set of configuration files used to build an automated CentOS 8 virtual machine images using [Packer](https://www.packer.io/).
This Packer configuration file allows you to build images for VMware Workstation and Oracle VM VirtualBox.
## Prerequisites
- [Packer](https://www.packer.io/downloads.html)
- <https://www.packer.io/intro/getting-started/install.html>
- A Hypervisor
- [VMware Workstation](https://www.vmware.com/products/workstation-pro.html)
- [Oracle VM VirtualBox](https://www.virtualbox.org/)
## How to use Packer
Commands to create an automated VM image:
To create a CentOS 8 VM image using VMware Workstation use the following commands:
```cmd
cd c:\packer-CentOS8
packer build -only=vmware-iso centos8.json
```
To create a CentOS 8 VM image using Oracle VM VirtualBox use the following commands:
```cmd
cd c:\packer-CentOS8
packer build -only=virtualbox-iso centos8.json
```
*If you omit the keyword "-only=" both the Workstation and Virtualbox VMs will be created.*
By default the .iso of CentOS 8 is pulled from <http://miroir.univ-paris13.fr/centos/8/isos/x86_64/CentOS-8.1.1911-x86_64-boot.iso>
You can change the URL to one closer to your build server. To do so change the **"iso_url"** parameter in the **"variables"** section of the centos8.json file.
```json
{
"variables": {
"iso_url": "http://miroir.univ-paris13.fr/centos/8/isos/x86_64/CentOS-8.1.1911-x86_64-boot.iso"
}
```
## Keyboard configuration
By default the keyboard is set to be US qwerty.
To switch it to something else edit the following file:
- ./http/ks.cfg
Set the `keyboard` parameter as desired, for example: `keyboard --vckeymap=fr --xlayouts='fr'`
## Default credentials
The default credentials for this VM image are:
|Username|Password|
|--------|--------|
|packer|packer|
|root|packer|

View File

@@ -1,29 +0,0 @@
##################################################################################
# VARIABLES
##################################################################################
# Virtual Machine Settings
vm_boot_wait = "5s"
vm_name = "fedora-41-small"
vm_id = "9101"
vm_cpu_sockets = "1"
vm_cpu_cores = "2"
vm_mem_size = "2048"
vm_disk_size = "8"
proxmox_bridge = "vmbr1"
proxmox_vlan = "71"
ssh_username = "wed"
# ISO Objects
iso_file = "Fedora-Server-netinst-x86_64-41-1.4.iso"
iso_checksum = "ca03867ab88fbe565b91ae518e6f7f83debe6415234f29ff2cc5634052840ce8"
iso_checksum_type = "sha256"
# iso_url = "https://mirror.rackspace.com/centos-stream/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-dvd1.iso"
# Scripts
shell_scripts = ["scripts/cleanup.sh"]

View File

@@ -1,132 +0,0 @@
##################################################################################
# LOCALS
##################################################################################
locals {
buildtime = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp())
}
packer {
required_plugins {
ansible = {
version = ">= 1.1.3"
source = "github.com/hashicorp/ansible"
}
name = {
version = "~> 1"
source = "github.com/hashicorp/proxmox"
}
}
}
##################################################################################
# SOURCE
##################################################################################
source "proxmox-iso" "fedora-kickstart" {
#insecure_skip_tls_verify = "${var.proxmox_insecure_verify}"
boot_iso {
type = "scsi"
iso_file = "${var.proxmox_iso_storage_pool}:iso/${var.iso_file}"
unmount = true
#iso_checksum = "sha512:33c08e56c83d13007e4a5511b9bf2c4926c4aa12fd5dd56d493c0653aecbab380988c5bf1671dbaea75c582827797d98c4a611f7fb2b131fbde2c677d5258ec9"
# iso_checksum = "${iso_checksum_type}:${var.iso_checksum}"
}
os = "l26"
bios = "ovmf"
vm_id = "${var.vm_id}"
efi_config {
efi_storage_pool = "${var.proxmox_vm_storage_pool}"
efi_type = "4m"
pre_enrolled_keys = true #false
}
http_directory = "http"
boot_command = [
"<up><wait>",
"e",
"<down><down><down><left>",
# leave a space from last arg
" inst.ks=http://{{.HTTPIP}}:{{.HTTPPort}}/ks.cfg <f10>"
]
boot_wait = "${var.vm_boot_wait}"
sockets = "${var.vm_cpu_sockets}"
cores = "${var.vm_cpu_cores}"
cpu_type = "host"
memory = "${var.vm_mem_size}"
scsi_controller = "virtio-scsi-single"
disks {
storage_pool = "${var.proxmox_vm_storage_pool}"
disk_size = "${var.vm_disk_size}G"
}
network_adapters {
model = "virtio"
bridge = "${var.proxmox_bridge}"
vlan_tag = "${var.proxmox_vlan}"
firewall = "true"
}
node = "${var.proxmox_node}"
username = "${var.proxmox_username}"
password = "${var.proxmox_password}"
proxmox_url = "https://${var.proxmox_node}.${var.proxmox_domain}:8006/api2/json"
ssh_timeout = "15m"
ssh_username = "${var.ssh_username}"
ssh_password = "${var.ssh_password}"
template_description = "Fedora 41-1.4, generated on ${timestamp()}"
template_name = "${var.vm_name}"
}
##################################################################################
# BUILD
##################################################################################
# inline = ["dnf -y update", "dnf -y install python-pip", "python3 -m pip install --upgrade pip", "alternatives --set python /usr/bin/python3", "pip3 install ansible"]
build {
sources = ["source.proxmox-iso.fedora-kickstart"]
#name = "${var.vm_mame}"
provisioner "shell" {
execute_command = "echo 'packer'|{{ .Vars }} sudo -S -E bash '{{ .Path }}'"
inline = [
"dnf -y update",
"dnf -y install python-pip",
"pip install ansible"
]
}
provisioner "file" {
source = "files/ansible.pub"
destination = "/tmp/ansible.pub"
}
provisioner "shell" {
execute_command = "echo 'packer'|{{ .Vars }} sudo -S -E bash '{{ .Path }}'"
inline = [
"mkdir /home/wed/.ssh",
"chown wed:wed /home/wed/.ssh",
"cat /tmp/ansible.pub > /home/wed/.ssh/authorized_keys",
"chmod 600 /home/wed/.ssh/authorized_keys",
"chown wed:wed /home/wed/.ssh/authorized_keys",
"rm /tmp/ansible.pub"
]
}
provisioner "ansible-local" {
playbook_file = "scripts/setup.yml"
}
provisioner "shell" {
execute_command = "echo 'packer'|{{ .Vars }} sudo -S -E bash '{{ .Path }}'"
scripts = [
"scripts/cleanup.sh"
]
}
}

View File

@@ -1 +0,0 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINnSM/9fO8rz/amqkyoGUzUKNNzzmtSXPwOCr1O9zKNO ansible

View File

@@ -1,70 +0,0 @@
# Kickstart file for Fedora 41 Server (Text-based Installation)
#
# For use with the Fedora Server netinstall ISO.
# Boot the installer with:
# linux /isolinux/vmlinuz inst.ks=http://<server>/<path>/ks.cfg
#
# For a local file on a USB drive, you can use:
# linux /isolinux/vmlinuz inst.ks=hd:LABEL=<USB_LABEL>:/ks.cfg
# Use text mode install
text
# Disable Initial Setup on first boot
firstboot --disable
# Keyboard layout
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# Network information
network --bootproto=dhcp --device=link --activate
network --hostname=fedora.localdomain
# Root password
rootpw $5$CXpezfLKTajPP7yI$VM8STd3QaHBTKMe2DLTmK5p.lEGbUYYZV8jGG3nxX2/ --iscrypted
# SELinux configuration
selinux --enforcing
# Do not configure the X Window System
skipx
# System timezone
timezone US/Chicago --utc
# Add a user named wed
user --groups=wheel --name=wed --password=$5$UOpZHG55fWCHlNSp$nFnpaVLb9enbQTebHo4SKBqolGr39SMYo2ZshHCe2d3 --iscrypted --gecos="wed"
# System bootloader configuration
bootloader --location=mbr --append="crashkernel=auto"
# Clear the Master Boot Record
zerombr
# Remove partitions
clearpart --all --initlabel
# Automatically create partitions using LVM
autopart --type=lvm
# Reboot after successful installation
reboot
%packages --ignoremissing
# dnf group info minimal-environment
@^minimal-environment
# Exclude unnecessary firmwares
-iwl*firmware
%end
%post --nochroot --logfile=/mnt/sysimage/root/ks-post.log
# Disable quiet boot and splash screen
sed --follow-symlinks -i "s/ rhgb quiet//" /mnt/sysimage/etc/default/grub
sed --follow-symlinks -i "s/ rhgb quiet//" /mnt/sysimage/boot/grub2/grubenv
# Passwordless sudo for the user 'wed'
echo "wed ALL=(ALL) NOPASSWD: ALL" >> /mnt/sysimage/etc/sudoers.d/wed
%end

View File

@@ -1,64 +0,0 @@
# Kickstart file for Fedora 41 Server (Text-based Installation)
#
# For use with the Fedora Server netinstall ISO.
# Boot the installer with:
# linux /isolinux/vmlinuz inst.ks=http://<server>/<path>/ks.cfg
#
# For a local file on a USB drive, you can use:
# linux /isolinux/vmlinuz inst.ks=hd:LABEL=<USB_LABEL>:/ks.cfg
# System language, keyboard layout, and timezone
lang en_US.UTF-8
keyboard us
timezone America/Chicago --isUtc
# Installation source
url --mirrorlist=https://mirrors.fedoraproject.org/mirrorlist?repo=fedora-41&arch=x86_64
# Use text mode installer
text
# Network configuration
# Using DHCP for automatic network configuration.
# For a static configuration, uncomment and modify the following lines:
# network --bootproto=static --device=eth0 --ip=192.168.1.10 --netmask=255.255.255.0 --gateway=192.168.1.1 --nameserver=8.8.8.8,8.8.4.4 --hostname=fedora-server
network --bootproto=dhcp --device=eth0 --onboot=on --ipv6=auto --hostname=fedora41-server
# Root password (encrypted)
# To generate an encrypted password, use:
# python -c 'import crypt; print(crypt.crypt("YourPassword", crypt.mksalt(crypt.METHOD_SHA512)))'
rootpw --iscrypted $6$your_encrypted_root_password_hash
# Disk partitioning
# This will erase the specified disk.
# --ondisk=sda can be changed to a more specific device like vda for virtual machines.
# --all will erase all partitions on the disk.
# LVM partitioning scheme is used for flexibility.
zerombr
clearpart --all --initlabel --drives=sda
autopart --type=lvm
# System services
# Disables services not typically required on a minimal server.
services --disabled="kdump,mdmonitor,mdmonitor-takeover" --enabled="sshd,chronyd"
# Package selection
# @^server-product-environment provides a minimal server installation.
# You can add additional packages as needed.
%packages
@^server-product-environment
-@standard
# Add essential command-line tools
vim-enhanced
tmux
git
%end
# Post-installation script
%post --log=/root/ks-post.log
echo "Fedora 41 Server installation complete." > /etc/motd
# Add any additional post-installation tasks here.
%end
# Reboot after installation
reboot

View File

@@ -1,20 +0,0 @@
##################################################################################
# VARIABLES
##################################################################################
# Credentials
proxmox_username = "root@pam"
proxmox_password = ""
ssh_username = "wed"
ssh_password = ""
# Proxmox Objects
proxmox_node = "pve03"
proxmox_domain = "int.mk-labs.cloud"
#proxmox_url = "https://${var.proxmox_node}.${proxmox_domain}:8006/api2/json"
proxmox_vm_storage_pool = "pve-templates"
#proxmox_insecure_connection = false #Default: true
proxmox_iso_storage_pool = "local"
#template_name = ""

View File

@@ -1,12 +0,0 @@
#!/bin/bash -eux
pip uninstall -y ansible
dnf clean all
# Zero out the rest of the free space using dd, then delete the written file.
#dd if=/dev/zero of=/EMPTY bs=1M
#rm -f /EMPTY
# Add `sync` so Packer doesn't quit too early, before the large file is deleted.
sync

View File

@@ -1,81 +0,0 @@
---
- name: "Setup.yml"
hosts: localhost
gather_facts: yes
become: yes
tasks:
- name: Colorize root shell prompt
lineinfile:
path: /root/.bashrc
line: 'export PS1="\[\033[38;5;11m\]\u\[$(tput sgr0)\]\[\033[38;5;15m\]@\h:\[$(tput sgr0)\]\[\033[38;5;6m\][\w]:\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]"'
state: present
- name: Alias vi to vim
lineinfile:
path: /root/.bashrc
line: "alias vi='vim'"
state: present
- name: Create vim configuration file
file:
path: /root/.vimrc
state: touch
owner: root
group: root
mode: 0644
- name: Configure vim
blockinfile:
path: /root/.vimrc
block: |
set nocompatible
set number
set autoindent
syntax on
highlight Comment ctermfg=LightCyan
marker: ""
state: present
- name: Disable GSSAPIAuthentication
lineinfile:
path: /etc/ssh/sshd_config
regexp: "^GSSAPIAuthentication"
line: "GSSAPIAuthentication no"
state: present
- name: Update CA bundle (RedHat)
get_url:
url: https://curl.haxx.se/ca/cacert.pem
dest: /etc/pki/tls/certs/ca-bundle.crt
force: yes
when: ansible_os_family == "RedHat"
- name: Install epel repo (RedHat)
dnf:
name: "epel-release"
state: latest
when: ansible_os_family == "RedHat"
- name: Install packages (RedHat)
dnf:
name: "{{ packages }}"
state: latest
vars:
packages:
- bash-completion
- curl
- git
- rsync
- screen
- tcpdump
- vim
- wget
when: ansible_os_family == "RedHat"
- name: Install open-vm-tools (RedHat)
dnf:
name: open-vm-tools
state: latest
when:
- ansible_os_family == "RedHat"
- ansible_virtualization_type == "VMware"

View File

@@ -1,144 +0,0 @@
# Proxmox variable definitions
variable "proxmox_username" {
type = string
description = "The username for authenticating to Proxmox."
default = ""
sensitive = true
}
variable "proxmox_password" {
type = string
description = "The plaintext password for authenticating to Proxmox."
default = ""
sensitive = true
}
variable "proxmox_node" {
type = string
description = "The Proxmox node to store the templates on."
default = ""
}
variable "proxmox_domain" {
type = string
description = "The domain the Proxmox node resizes in."
default = ""
}
variable "proxmox_insecure_verify" {
type = bool
description = "If true, does not validate the proxmox server's TLS certificate."
default = true
}
variable "proxmox_vm_storage_pool" {
type = string
description = "The storage pool where the VM will live."
default = ""
}
# Virtual Machine variables
variable "vm_name" {
type = string
description = "The template vm name"
default = ""
}
variable "vm_id" {
type = number
description = "The ID of virtual machine."
}
variable "vm_cpu_sockets" {
type = number
description = "The number of virtual CPUs sockets."
default = "1"
}
variable "vm_cpu_cores" {
type = number
description = "The number of virtual CPUs cores per socket."
default = "1"
}
variable "vm_mem_size" {
type = number
description = "The size for the virtual memory in MB."
}
variable "vm_disk_size" {
type = number
description = "The size of the primary virtual disk in GiB."
}
variable "proxmox_bridge" {
type = string
description = "The Proxmox bridge the NIC connects to."
}
variable "proxmox_vlan" {
type = number
description = "The VLAN the NIC is on."
}
variable "vm_boot_wait" {
type = string
description = "The time to wait before boot (in seconds)."
default = ""
}
variable "shell_scripts" {
type = list(string)
description = "A list of scripts."
default = []
}
# ISO Objects
variable "proxmox_iso_storage_pool" {
type = string
description = "The storage pool where the ISO is located."
default = ""
}
variable "iso_url" {
type = string
description = "The url to retrieve the iso image"
default = ""
}
variable "iso_file" {
type = string
description = "The file name of the guest operating system ISO image installation media."
default = ""
}
variable "iso_checksum" {
type = string
description = "The checksum of the ISO image."
default = ""
}
variable "iso_checksum_type" {
type = string
description = "The checksum type of the ISO image. Ex: sha256"
default = ""
}
# SSH info
variable "ssh_username" {
type = string
description = "The username to use to authenticate over SSH."
default = ""
sensitive = true
}
variable "ssh_password" {
type = string
description = "The plaintext password to use to authenticate over SSH."
default = ""
sensitive = true
}

View File

@@ -1,35 +0,0 @@
##################################################################################
# VARIABLES
##################################################################################
# HTTP Settings
http_directory = "http"
# Virtual Machine Settings
vm_name = "centos9-large"
vm_guest_os_type = "centos8_64Guest"
vm_version = 19
vm_firmware = "efi"
vm_cdrom_type = "sata"
vm_cpu_sockets = 1
vm_cpu_cores = 1
vm_mem_size = 2048
vm_disk_size = 51200
thin_provision = true
disk_eagerly_scrub = false
vm_disk_controller_type = ["pvscsi"]
vm_network_card = "vmxnet3"
vm_boot_wait = "5s"
ssh_username = "wed"
ssh_password = "1mag!ne3R"
# ISO Objects
iso_checksum = "ca03867ab88fbe565b91ae518e6f7f83debe6415234f29ff2cc5634052840ce8"
iso_checksum_type = "sha256"
iso_url = "https://mirror.rackspace.com/centos-stream/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-dvd1.iso"
# Scripts
shell_scripts = ["scripts/cleanup.sh"]

View File

@@ -1,35 +0,0 @@
##################################################################################
# VARIABLES
##################################################################################
# HTTP Settings
http_directory = "http"
# Virtual Machine Settings
vm_name = "centos9-medium"
vm_guest_os_type = "centos8_64Guest"
vm_version = 19
vm_firmware = "efi"
vm_cdrom_type = "sata"
vm_cpu_sockets = 1
vm_cpu_cores = 1
vm_mem_size = 2048
vm_disk_size = 25600
thin_provision = true
disk_eagerly_scrub = false
vm_disk_controller_type = ["pvscsi"]
vm_network_card = "vmxnet3"
vm_boot_wait = "5s"
ssh_username = "wed"
ssh_password = "1mag!ne3R"
# ISO Objects
iso_checksum = "ca03867ab88fbe565b91ae518e6f7f83debe6415234f29ff2cc5634052840ce8"
iso_checksum_type = "sha256"
iso_url = "https://mirror.rackspace.com/centos-stream/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-dvd1.iso"
# Scripts
shell_scripts = ["scripts/cleanup.sh"]

View File

@@ -1,35 +0,0 @@
##################################################################################
# VARIABLES
##################################################################################
# HTTP Settings
http_directory = "http"
# Virtual Machine Settings
vm_name = "centos9-large"
vm_guest_os_type = "centos8_64Guest"
vm_version = 19
vm_firmware = "efi"
vm_cdrom_type = "sata"
vm_cpu_sockets = 1
vm_cpu_cores = 1
vm_mem_size = 2048
vm_disk_size = 102400
thin_provision = true
disk_eagerly_scrub = false
vm_disk_controller_type = ["pvscsi"]
vm_network_card = "vmxnet3"
vm_boot_wait = "5s"
ssh_username = "wed"
ssh_password = "1mag!ne3R"
# ISO Objects
iso_checksum = "ca03867ab88fbe565b91ae518e6f7f83debe6415234f29ff2cc5634052840ce8"
iso_checksum_type = "sha256"
iso_url = "https://mirror.rackspace.com/centos-stream/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-dvd1.iso"
# Scripts
shell_scripts = ["scripts/cleanup.sh"]

View File

@@ -0,0 +1,70 @@
---
- name: Create VM ID from IP address for Proxmox hosts
hosts: all
gather_facts: false
tasks:
- name: Create Proxmox VMs
delegate_to: "localhost"
when: platform is defined and platform == "proxmox"
block:
- name: Create VM ID from IP address
ansible.builtin.set_fact:
vm_id: "{{ ip_address.split('.')[-2] }}{{ '%03d' % (ip_address.split('.')[-1] | int) }}"
- name: Clone VM with source vmid and target newid and raw format
community.proxmox.proxmox_kvm:
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_password }}"
api_host: "{{ proxmox_host }}"
clone: "{{ vm_clone_source }}"
newid: "{{ vm_id }}"
name: "{{ inventory_hostname }}"
node: "{{ proxmox_clone_node }}"
storage: "{{ vm_storage }}"
format: raw
- name: Retrieve information about specific VM by name and get current configuration
community.proxmox.proxmox_vm_info:
api_user: "{{ proxmox_user }}"
api_password: "{{ proxmox_password }}"
api_host: "{{ proxmox_host }}"
name: "{{ inventory_hostname }}"
config: current
register: proxmox_vm_info
- name: Extract net0 information
set_fact:
vm_net0: "{{ proxmox_vm_info.proxmox_vms[0].config.net0 }}"
- name: Extract MAC address using regex
set_fact:
vm_mac_address: "{{ vm_net0 | regex_search('([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}') }}"
# Create DNS Entry
# Create DHCP Reservation
#
# - name: Start VM
# community.proxmox.proxmox_kvm:
# api_user: "{{ proxmox_user }}"
# api_password: "{{ proxmox_password }}"
# api_host: "{{ proxmox_host }}"
# name: "{{ inventory_hostname }}"
# node: "{{ proxmox_target_node }}"
# state: started
# - name: Add VM to HA group
# community.proxmox.proxmox_cluster_ha_resources:
# api_user: "{{ proxmox_user }}"
# api_password: "{{ proxmox_password }}"
# api_host: "{{ proxmox_host }}"
# name: vm:"{{ vm_id }}"
# state: "present"
# group: "{{ ha_group }}"
# max_relocate: 2
# max_restart: 2
# - name: Set hostname of cloned VM
# delegate_to: "{{ inventory_hostname }}"
# ansible.builtin.hostname:
# name: "{{ hostname }}"

View File

@@ -2,5 +2,5 @@
# file: host_vars/backup/vars # file: host_vars/backup/vars
# mac_address: "98:b7:85:1e:c6:f1" # mac_address: "98:b7:85:1e:c6:f1"
ip_address: "10.1.71.9" ip_address: "10.1.71.9"
hostname: "backup.{{ base_domain }}" hostname: "{{ inventory_hostname }}.{{ base_domain }}"
# primary_interface: "enp1s0f0" # primary_interface: "enp1s0f0"

View File

@@ -5,7 +5,7 @@
# primary_interface: "enp1s0f0" # primary_interface: "enp1s0f0"
mac_address: "BC:24:11:03:A9:7B" mac_address: "BC:24:11:03:A9:7B"
ip_address: 10.1.71.211 ip_address: 10.1.71.211
hostname: "docker01.{{ base_domain }}" hostname: "{{ inventory_hostname }}.{{ base_domain }}"
# Software # Software
#terraform_version: "1.11.3" #terraform_version: "1.11.3"

View File

@@ -5,7 +5,7 @@
# primary_interface: "enp1s0f0" # primary_interface: "enp1s0f0"
# mac_address: "98:b7:85:1e:c6:f1" # mac_address: "98:b7:85:1e:c6:f1"
#ip_address: 10.1.71.51 #ip_address: 10.1.71.51
hostname: "infra01.{{ base_domain }}" hostname: "{{ inventory_hostname }}.{{ base_domain }}"
# Software # Software
terraform_version: "1.11.3" terraform_version: "1.11.3"

View File

@@ -5,7 +5,7 @@
# primary_interface: "enp1s0f0" # primary_interface: "enp1s0f0"
# mac_address: "98:b7:85:1e:c6:f1" # mac_address: "98:b7:85:1e:c6:f1"
ip_address: 10.1.71.7 ip_address: 10.1.71.7
hostname: "matchbox.{{ base_domain }}" hostname: "{{ inventory_hostname }}.{{ base_domain }}"
# Software # Software
#terraform_version: "1.11.3" #terraform_version: "1.11.3"

View File

@@ -5,7 +5,7 @@
# primary_interface: "enp1s0f0" # primary_interface: "enp1s0f0"
mac_address: "BC:24:11:1B:BB:92" mac_address: "BC:24:11:1B:BB:92"
ip_address: 10.1.71.81 ip_address: 10.1.71.81
hostname: "n8n.{{ base_domain }}" hostname: "{{ inventory_hostname }}.{{ base_domain }}"
# Software # Software
#terraform_version: "1.11.3" #terraform_version: "1.11.3"

View File

@@ -0,0 +1,19 @@
---
# file: host_vars/prometheus/vars
# VM Definition
platform: "proxmox"
proxmox_clone_node: "pve03"
vm_clone_source: "fedora-42-large"
vm_storage: "pve-general"
ha_group: "pv03"
# Networking
ip_address: 10.1.71.249
# primary_interface: "enp1s0f0"
# mac_address: "BC:24:11:03:A9:7B" # convert this to a proxmox read for VMs
# Software
#terraform_version: "1.11.3"
hostname: "{{ inventory_hostname }}.{{ base_domain }}" #change variable to fqdn

View File

@@ -3,5 +3,5 @@
# mac_address: "98:b7:85:1e:c6:f1" # mac_address: "98:b7:85:1e:c6:f1"
#ip_address: "10.1.71.51" #ip_address: "10.1.71.51"
ip_address: "10.10.21.51" ip_address: "10.10.21.51"
hostname: "pve01.{{ base_domain }}" hostname: "{{ inventory_hostname }}.{{ base_domain }}"
# primary_interface: "enp1s0f0" # primary_interface: "enp1s0f0"

View File

@@ -3,5 +3,5 @@
# mac_address: "98:b7:85:1e:c6:f1" # mac_address: "98:b7:85:1e:c6:f1"
#ip_address: "10.1.71.52" #ip_address: "10.1.71.52"
ip_address: "10.10.21.52" ip_address: "10.10.21.52"
hostname: "pve02.{{ base_domain }}" hostname: "{{ inventory_hostname }}.{{ base_domain }}"
# primary_interface: "enp1s0f0" # primary_interface: "enp1s0f0"

View File

@@ -3,5 +3,5 @@
# mac_address: "98:b7:85:1e:c6:f1" # mac_address: "98:b7:85:1e:c6:f1"
#ip_address: "10.1.71.53" #ip_address: "10.1.71.53"
ip_address: "10.10.21.53" ip_address: "10.10.21.53"
hostname: "pve03.{{ base_domain }}" hostname: "{{ inventory_hostname }}.{{ base_domain }}"
# primary_interface: "enp1s0f0" # primary_interface: "enp1s0f0"

View File

@@ -5,7 +5,7 @@
# primary_interface: "enp1s0f0" # primary_interface: "enp1s0f0"
mac_address: "BC:24:11:1C:95:1B" mac_address: "BC:24:11:1C:95:1B"
ip_address: 10.1.71.91 ip_address: 10.1.71.91
hostname: "sql01.{{ base_domain }}" hostname: "{{ inventory_hostname }}.{{ base_domain }}"
# Software # Software
#terraform_version: "1.11.3" #terraform_version: "1.11.3"

View File

@@ -1,37 +1,44 @@
# file: inventory.yml # file: inventory.yml
proxmox: proxmox:
hosts: hosts:
pve0[1:3]: pve0[1:3]:
unbound_servers: unbound_servers:
hosts: hosts:
unbound02: unbound02:
backup_servers: backup_servers:
hosts: hosts:
backup: backup:
freeipa: freeipa:
hosts: hosts:
infra01: infra01:
matchbox: matchbox:
hosts: hosts:
infra01: infra01:
hub_cluster: hub_cluster:
hosts: hosts:
ocp-hub: ocp-hub:
sql_servers: sql_servers:
hosts: hosts:
sql01: sql01:
n8n_servers: n8n_servers:
hosts: hosts:
n8n: n8n:
docker_servers: docker_servers:
hosts: hosts:
docker01: docker01:
observer:
hosts:
prometheus:
target:
hosts:
prometheus:

View File

@@ -0,0 +1,15 @@
- name: Install Observability stack (targets)
hosts: target
tags:
- monitoring
- target
roles:
- ../roles/target
- name: Install Observability stack (observer)
hosts: observer
tags:
- monitoring
- observer
roles:
- ../roles/observer

View File

@@ -0,0 +1,11 @@
---
prometheus_version: v2.40.1
grafana_version: "9.2.5"
alertmanager_version: v0.24.0
#alertmanager_smtp_password: !vault |
$ANSIBLE_VAULT;1.1;AES256
64306663363562356132323065396635636630373031303739323666373262663961393132316333
6135653763363566303331313639633030623530646239310a353236343035643132646230333466
36336439376131333630346563323833313164353265313264643232373465633561663331396133
3163303166373166390a396131303239356139653063616437363933333130393563646338663933
3966

View File

@@ -0,0 +1,8 @@
apiVersion: 1
providers:
- name: Pre-loaded local dashboards
type: file
options:
foldersFromFilesStructure: true
path: /var/lib/grafana/dashboards

View File

@@ -0,0 +1,814 @@
{
"__inputs": [
{
"name": "DS_PROMETHEUS",
"label": "prometheus",
"description": "Prometheus as the datasource is obligatory",
"type": "datasource",
"pluginId": "prometheus",
"pluginName": "Prometheus"
}
],
"__requires": [
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "7.4.5"
},
{
"type": "panel",
"id": "graph",
"name": "Graph",
"version": ""
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"version": "1.0.0"
},
{
"type": "panel",
"id": "table",
"name": "Table",
"version": ""
}
],
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": 14282,
"graphTooltip": 0,
"id": null,
"iteration": 1617715580880,
"links": [],
"panels": [
{
"collapsed": false,
"datasource": "Prometheus",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 0
},
"id": 8,
"panels": [],
"title": "CPU",
"type": "row"
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 7,
"w": 24,
"x": 0,
"y": 1
},
"hiddenSeries": false,
"id": 15,
"legend": {
"alignAsTable": true,
"avg": true,
"current": false,
"max": true,
"min": false,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null as zero",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.4.5",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": true,
"steppedLine": false,
"targets": [
{
"expr": "sum(rate(container_cpu_usage_seconds_total{instance=~\"$host\",name=~\"$container\",name=~\".+\"}[5m])) by (name) *100",
"hide": false,
"interval": "",
"legendFormat": "{{name}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "CPU Usage",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:606",
"format": "percent",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"$$hashKey": "object:607",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"collapsed": false,
"datasource": "Prometheus",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 8
},
"id": 11,
"panels": [],
"title": "Memory",
"type": "row"
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 9
},
"hiddenSeries": false,
"id": 9,
"legend": {
"alignAsTable": true,
"avg": true,
"current": false,
"max": true,
"min": false,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null as zero",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.4.5",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": true,
"steppedLine": false,
"targets": [
{
"expr": "sum(container_memory_rss{instance=~\"$host\",name=~\"$container\",name=~\".+\"}) by (name)",
"hide": false,
"interval": "",
"legendFormat": "{{name}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Memory Usage",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:606",
"format": "bytes",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"$$hashKey": "object:607",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 9
},
"hiddenSeries": false,
"id": 14,
"legend": {
"alignAsTable": true,
"avg": true,
"current": false,
"max": true,
"min": false,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null as zero",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.4.5",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": true,
"steppedLine": false,
"targets": [
{
"expr": "sum(container_memory_cache{instance=~\"$host\",name=~\"$container\",name=~\".+\"}) by (name)",
"hide": false,
"interval": "",
"legendFormat": "{{name}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Memory Cached",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:606",
"format": "bytes",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"$$hashKey": "object:607",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"collapsed": false,
"datasource": "Prometheus",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 17
},
"id": 2,
"panels": [],
"title": "Network",
"type": "row"
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 18
},
"hiddenSeries": false,
"id": 4,
"legend": {
"alignAsTable": true,
"avg": true,
"current": false,
"hideEmpty": false,
"hideZero": false,
"max": true,
"min": false,
"rightSide": true,
"show": true,
"sideWidth": null,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.4.5",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "sum(rate(container_network_receive_bytes_total{instance=~\"$host\",name=~\"$container\",name=~\".+\"}[5m])) by (name)",
"hide": false,
"interval": "",
"legendFormat": "{{name}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Received Network Traffic",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:674",
"format": "Bps",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"$$hashKey": "object:675",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"custom": {}
},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 18
},
"hiddenSeries": false,
"id": 6,
"legend": {
"alignAsTable": true,
"avg": true,
"current": false,
"max": true,
"min": false,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.4.5",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "sum(rate(container_network_transmit_bytes_total{instance=~\"$host\",name=~\"$container\",name=~\".+\"}[5m])) by (name)",
"interval": "",
"legendFormat": "{{name}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Sent Network Traffic",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:832",
"format": "Bps",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"$$hashKey": "object:833",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"collapsed": false,
"datasource": "Prometheus",
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 26
},
"id": 19,
"panels": [],
"title": "Misc",
"type": "row"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"custom": {
"align": null,
"filterable": false
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "id"
},
"properties": [
{
"id": "custom.width",
"value": 260
}
]
},
{
"matcher": {
"id": "byName",
"options": "Running"
},
"properties": [
{
"id": "unit",
"value": "d"
},
{
"id": "decimals",
"value": 1
},
{
"id": "custom.displayMode",
"value": "color-text"
},
{
"id": "color",
"value": {
"fixedColor": "dark-green",
"mode": "fixed"
}
}
]
}
]
},
"gridPos": {
"h": 10,
"w": 24,
"x": 0,
"y": 27
},
"id": 17,
"options": {
"showHeader": true,
"sortBy": []
},
"pluginVersion": "7.4.5",
"targets": [
{
"expr": "(time() - container_start_time_seconds{instance=~\"$host\",name=~\"$container\",name=~\".+\"})/86400",
"format": "table",
"instant": true,
"interval": "",
"legendFormat": "{{name}}",
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "Containers Info",
"transformations": [
{
"id": "filterFieldsByName",
"options": {
"include": {
"names": [
"container_label_com_docker_compose_project",
"container_label_com_docker_compose_project_working_dir",
"image",
"instance",
"name",
"Value",
"container_label_com_docker_compose_service"
]
}
}
},
{
"id": "organize",
"options": {
"excludeByName": {},
"indexByName": {},
"renameByName": {
"Value": "Running",
"container_label_com_docker_compose_project": "Label",
"container_label_com_docker_compose_project_working_dir": "Working dir",
"container_label_com_docker_compose_service": "Service",
"image": "Registry Image",
"instance": "Instance",
"name": "Name"
}
}
}
],
"type": "table"
}
],
"schemaVersion": 27,
"style": "dark",
"tags": ["cadvisor", "docker"],
"templating": {
"list": [
{
"allValue": ".*",
"current": {},
"datasource": "Prometheus",
"definition": "label_values({__name__=~\"container.*\"},instance)",
"description": null,
"error": null,
"hide": 0,
"includeAll": true,
"label": "Host",
"multi": false,
"name": "host",
"options": [],
"query": {
"query": "label_values({__name__=~\"container.*\"},instance)",
"refId": "Prometheus-host-Variable-Query"
},
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 5,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
},
{
"allValue": ".*",
"current": {},
"datasource": "Prometheus",
"definition": "label_values({__name__=~\"container.*\", instance=~\"$host\"},name)",
"description": null,
"error": null,
"hide": 0,
"includeAll": true,
"label": "Container",
"multi": false,
"name": "container",
"options": [],
"query": {
"query": "label_values({__name__=~\"container.*\", instance=~\"$host\"},name)",
"refId": "Prometheus-container-Variable-Query"
},
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
}
]
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "Cadvisor exporter",
"uid": "pMEd7m0Mz",
"version": 1,
"description": "Simple exporter for cadvisor only"
}

View File

@@ -0,0 +1,7 @@
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://192.168.0.1:9090

View File

@@ -0,0 +1,11 @@
groups:
- name: AllInstances
rules:
- alert: InstanceDown
expr: up == 0
for: 1m
annotations:
title: 'Instance {{ $labels.instance }} down'
description: '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 1 minute.'
labels:
severity: 'critical'

View File

@@ -0,0 +1,28 @@
global:
scrape_interval: 15s
scrape_configs:
- job_name: prometheus
scrape_interval: 30s
static_configs:
- targets: ["localhost:9090"]
- job_name: node-exporter
scrape_interval: 30s
static_configs:
- targets:
["192.168.0.1:9100", "192.168.0.10:9100", "192.168.0.11:9100"]
- job_name: cadvisor
scrape_interval: 30s
static_configs:
- targets: ["192.168.0.1:9101", "192.168.0.11:9101"]
rule_files:
- prometheus_alerts_rules.yml
alerting:
alertmanagers:
- static_configs:
- targets:
- 192.168.0.1:9093

View File

@@ -0,0 +1,85 @@
- name: Create Folder /srv/prometheus if not exist
file:
path: /srv/prometheus
mode: 0755
state: directory
- name: Create Folder /srv/grafana if not exist
file:
path: /srv/grafana
mode: 0755
state: directory
- name: Create Folder /srv/alertmanager if not exist
file:
path: /srv/alertmanager
mode: 0755
state: directory
- name: Create prometheus configuration file
copy:
dest: /srv/prometheus/prometheus.yml
src: prometheus_main.yml
mode: 0644
- name: Create prometheus alert configuration file
copy:
dest: /srv/prometheus/prometheus_alerts_rules.yml
src: prometheus_alerts_rules.yml
mode: 0644
- name: Create grafana configuration files
copy:
dest: /srv/
src: grafana
mode: 0644
- name: Create alertmanager configuration file
template:
dest: /srv/alertmanager/alertmanager.yml
src: alertmanager/alertmanager.j2
mode: 0644
- name: Create Prometheus container
docker_container:
name: prometheus
restart_policy: always
image: prom/prometheus:
volumes:
- /srv/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- /srv/prometheus/prometheus_alerts_rules.yml:/etc/prometheus/prometheus_alerts_rules.yml
- prometheus_main_data:/prometheus
command: >
--config.file=/etc/prometheus/prometheus.yml
--storage.tsdb.path=/prometheus
--web.console.libraries=/etc/prometheus/console_libraries
--web.console.templates=/etc/prometheus/consoles
--web.enable-lifecycle
published_ports: "9090:9090"
- name: Create Grafana container
docker_container:
name: grafana
restart_policy: always
image: grafana/grafana:
volumes:
- grafana-data:/var/lib/grafana
- /srv/grafana/provisioning:/etc/grafana/provisioning
- /srv/grafana/dashboards:/var/lib/grafana/dashboards
env:
GF_AUTH_ANONYMOUS_ENABLED: "true"
GF_AUTH_ANONYMOUS_ORG_ROLE: "Admin"
published_ports: "3000:3000"
- name: Create Alertmanager container
docker_container:
name: alertmanager
restart_policy: always
image: prom/alertmanager:
volumes:
- alertmanager-data:/data
- /srv/alertmanager:/config
command: >
--config.file=/config/alertmanager.yml
--log.level=debug
published_ports: "9093:9093"

View File

@@ -0,0 +1,13 @@
route:
receiver: "mail"
repeat_interval: 4h
group_by: [ alertname ]
receivers:
- name: "mail"
email_configs:
- smarthost: "outlook.office365.com:587"
auth_username: "test@padok.fr"
auth_password: "{{ alertmanager_smtp_password }}"
from: "test@padok.fr"
to: "test@padok.fr"

View File

@@ -0,0 +1,3 @@
---
node_exporter_version: v1.4.0
cadvisor_version: v0.46.0

View File

@@ -0,0 +1,29 @@
---
- name: Create NodeExporter
docker_container:
name: node-exporter
restart_policy: always
image: prom/node-exporter:{{ node_exporter_version }}
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command: >
--path.procfs=/host/proc
--path.rootfs=/rootfs
--path.sysfs=/host/sys
--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)
published_ports: "9100:9100"
- name: Create cAdvisor
docker_container:
name: cadvisor
restart_policy: always
image: gcr.io/cadvisor/cadvisor:{{ cadvisor_version }}
volumes:
- /:/rootfs:ro
- /var/run:/var/run:ro
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
- /dev/disk/:/dev/disk:ro
published_ports: "9101:8080"

View File

@@ -1,32 +0,0 @@
---
- name: Run all tasks necessary to configure matchbox to install the cluster
hosts: all
#connection: local
gather_facts: false
tasks:
# - name: Print vars for debugging
# ansible.builtin.debug:
# msg: System {{ hostvars['infra01'].matchbox_assets }} / {{ hostvars['ocp-hub'].cluster_name }}
# - name: Print vars for debugging 2
# ansible.builtin.debug:
# msg: System {{ groups }}
# - name: Print vars for debugging 3
# ansible.builtin.debug:
# msg: System {{ groups['hub-cluster'][0] }}
# - name: Print vars for debugging 4
# ansible.builtin.debug:
# msg: System {{ hostvars[groups['hub-cluster'][0]].cluster_name }}
# - name: Print all available facts
# ansible.builtin.debug:
# var: ansible_facts
- name: Print host IP address if defined
debug:
msg: "Host {{ inventory_hostname }} has IP address: {{ hostvars[inventory_hostname].ip_address | default('Not defined') }}"
when: hostvars[inventory_hostname].ip_address is defined

View File

@@ -1,102 +0,0 @@
---
- name: Test IP address parsing - extract last two octets
hosts: localhost
gather_facts: false
vars:
test_ip: "192.168.1.100"
tasks:
- name: Method 1 - Using split and join
ansible.builtin.set_fact:
last_two_octets_1: "{{ test_ip.split('.')[-2:] | join('.') }}"
- name: Display results
ansible.builtin.debug:
msg: |
Original IP: {{ test_ip }}
Method 1 (split + join): {{ last_two_octets_1 }}
- name: Test with different IP addresses
ansible.builtin.set_fact:
test_ips:
- "10.0.0.1"
- "172.16.254.1"
- "192.168.100.200"
- "8.8.8.8"
- name: Process multiple IPs
ansible.builtin.set_fact:
results: "{{ results | default([]) + [{'ip': item, 'last_two': item.split('.')[-2:] | join('.')}] }}"
loop: "{{ test_ips }}"
- name: Display all results
ansible.builtin.debug:
msg: "{{ results }}"
# New tasks for 3-digit formatting
- name: Method 1 - Format last octet to 3 digits using zfill
ansible.builtin.set_fact:
last_two_octets_3digits_1: "{{ test_ip.split('.')[-2] }}.{{ (test_ip.split('.')[-1] | int) | string | zfill(3) }}"
- name: Method 2 - Format last octet to 3 digits using format
ansible.builtin.set_fact:
last_two_octets_3digits_2: "{{ test_ip.split('.')[-2] }}.{{ '%03d' % (test_ip.split('.')[-1] | int) }}"
- name: Method 3 - Format last octet to 3 digits using sprintf
ansible.builtin.set_fact:
last_two_octets_3digits_3: "{{ test_ip.split('.')[-2] }}.{{ (test_ip.split('.')[-1] | int) | string | sprintf('%03d') }}"
- name: Display 3-digit formatting results
ansible.builtin.debug:
msg: |
Original IP: {{ test_ip }}
Method 1 (zfill): {{ last_two_octets_3digits_1 }}
Method 2 (format): {{ last_two_octets_3digits_2 }}
Method 3 (sprintf): {{ last_two_octets_3digits_3 }}
- name: Test 3-digit formatting with different IPs
ansible.builtin.set_fact:
test_ips_3digits:
- "10.0.0.1"
- "172.16.254.1"
- "192.168.100.200"
- "8.8.8.8"
- "192.168.1.10"
- "10.0.0.255"
- name: Process multiple IPs with 3-digit formatting
ansible.builtin.set_fact:
results_3digits: "{{ results_3digits | default([]) + [{'ip': item, 'last_two_3digits': item.split('.')[-2] + '.' + ('%03d' % (item.split('.')[-1] | int))}] }}"
loop: "{{ test_ips_3digits }}"
- name: Display all 3-digit results
ansible.builtin.debug:
msg: "{{ results_3digits }}"
# VM ID creation without dot separator
- name: Create vm_id using format (no dot separator)
ansible.builtin.set_fact:
vm_id: "{{ test_ip.split('.')[-2] }}{{ '%03d' % (test_ip.split('.')[-1] | int) }}"
- name: Create vm_id using sprintf (no dot separator)
ansible.builtin.set_fact:
vm_id_sprintf: "{{ test_ip.split('.')[-2] }}{{ (test_ip.split('.')[-1] | int) | string | sprintf('%03d') }}"
- name: Display vm_id results
ansible.builtin.debug:
msg: |
Original IP: {{ test_ip }}
VM ID (format): {{ vm_id }}
VM ID (sprintf): {{ vm_id_sprintf }}
- name: Test vm_id with different IPs
ansible.builtin.set_fact:
vm_id_results: "{{ vm_id_results | default([]) + [{'ip': item, 'vm_id': item.split('.')[-2] + ('%03d' % (item.split('.')[-1] | int))}] }}"
loop: "{{ test_ips_3digits }}"
- name: Display all vm_id results
ansible.builtin.debug:
msg: "{{ vm_id_results }}"