default image: sool9. cloud-init add local repo

This commit is contained in:
m0duspwnens
2025-01-16 08:43:46 -05:00
parent 837fbab96d
commit e8546b82f8
2 changed files with 20 additions and 5 deletions

View File

@@ -13,7 +13,7 @@ but can also be run manually if needed.
CLI Examples: CLI Examples:
# Perform complete environment setup (creates VM named 'so-ol9' with 220G disk by default) # Perform complete environment setup (creates VM named 'sool9' with 220G disk by default)
salt-run setup_hypervisor.setup_environment salt-run setup_hypervisor.setup_environment
# Setup with custom VM name (uses default 220G disk) # Setup with custom VM name (uses default 220G disk)
@@ -38,6 +38,7 @@ import os
import pwd import pwd
import requests import requests
import salt.utils.files import salt.utils.files
import socket
import sys import sys
import time import time
from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives import serialization
@@ -253,7 +254,7 @@ def _check_vm_exists(vm_name: str) -> bool:
log.info("MAIN: VM %s already exists", vm_name) log.info("MAIN: VM %s already exists", vm_name)
return exists return exists
def setup_environment(vm_name: str = 'so-ol9', disk_size: str = '220G'): def setup_environment(vm_name: str = 'sool9', disk_size: str = '220G'):
""" """
Main entry point to set up the hypervisor environment. Main entry point to set up the hypervisor environment.
This includes downloading the base image, generating SSH keys for remote access, This includes downloading the base image, generating SSH keys for remote access,
@@ -261,7 +262,7 @@ def setup_environment(vm_name: str = 'so-ol9', disk_size: str = '220G'):
Args: Args:
vm_name (str, optional): Name of the VM to create as part of environment setup. vm_name (str, optional): Name of the VM to create as part of environment setup.
Defaults to 'so-ol9'. Defaults to 'sool9'.
disk_size (str, optional): Size of the VM disk with unit. disk_size (str, optional): Size of the VM disk with unit.
Defaults to '220G'. Defaults to '220G'.
@@ -390,6 +391,9 @@ def create_vm(vm_name: str, disk_size: str = '220G'):
log.error("CREATEVM: Failed to read SSH public key: %s", str(e)) log.error("CREATEVM: Failed to read SSH public key: %s", str(e))
return {'success': False, 'error': 'Failed to read SSH public key'} return {'success': False, 'error': 'Failed to read SSH public key'}
# Get hostname for repo configuration
manager_hostname = socket.gethostname()
# Create meta-data # Create meta-data
meta_data = f"""instance-id: {vm_name} meta_data = f"""instance-id: {vm_name}
local-hostname: {vm_name} local-hostname: {vm_name}
@@ -404,6 +408,7 @@ preserve_hostname: False
hostname: {vm_name} hostname: {vm_name}
fqdn: {vm_name}.local fqdn: {vm_name}.local
# The passwd hash will be removed at release and is being used for debugging during development
users: users:
- default - default
- name: soqemussh - name: soqemussh
@@ -429,6 +434,16 @@ timezone: UTC
packages: packages:
- qemu-guest-agent - qemu-guest-agent
write_files:
- path: /etc/yum.repos.d/securityonion.repo
content: |
[securityonion]
name=Security Onion Repo
baseurl=https://{manager_hostname}/repo
enabled=1
gpgcheck=1
sslverify=0
runcmd: runcmd:
- systemctl enable --now qemu-guest-agent - systemctl enable --now qemu-guest-agent
- systemctl enable --now serial-getty@ttyS0.service - systemctl enable --now serial-getty@ttyS0.service

View File

@@ -6,9 +6,9 @@
{%- for role, hosts in HYPERVISORS.items() %} {%- for role, hosts in HYPERVISORS.items() %}
{%- for host in hosts.keys() -%} {%- for host in hosts.keys() -%}
core-{{host}}: sool9-{{host}}:
provider: kvm-ssh-{{host}} provider: kvm-ssh-{{host}}
base_domain: coreol9 base_domain: sool9
ip_source: qemu-agent ip_source: qemu-agent
ssh_username: soqemussh ssh_username: soqemussh
private_key: /home/soqemussh/.ssh/id_ed25519 private_key: /home/soqemussh/.ssh/id_ed25519