Added this repo

This commit is contained in:
2024-09-19 13:29:35 +03:00
commit 5ae5fe2586
47 changed files with 1265 additions and 0 deletions

View File

@ -0,0 +1 @@
---

View File

@ -0,0 +1 @@
---

View File

@ -0,0 +1,21 @@
---
- name: Copy from template boot.ipxe
ansible.builtin.template:
src: boot.ipxe.j2
dest: "{{ path_ipxe_boot }}/boot_{{ vm_macaddress }}.ipxe"
- name: Copy from template preseed.cfg
ansible.builtin.template:
src: preseed.cfg.j2
dest: "{{ path_preseed }}/preseed_{{ vm_macaddress }}.cfg"
- name: Add config to DHCP server
ansible.builtin.lineinfile:
path: "{{ path_dhcp_conf }}"
line: 'host {{ vm_name | regex_replace("\..*","") }} { hardware ethernet {{ vm_macaddress }}; if exists user-class and option user-class = "iPXE" { filename "http://${next-server}:80/.boot/boot_{{ vm_macaddress }}.ipxe";} else { filename "undionly.kpxe"; }}'
- name: Restart DHCP service
ansible.builtin.systemd_service:
state: restarted
name: isc-dhcp-server

View File

@ -0,0 +1,14 @@
---
- name: Delete config to DHCP server
ansible.builtin.lineinfile:
path: "{{ path_dhcp_conf }}"
state: absent
line: 'host {{ vm_name | regex_replace("\..*","") }} { hardware ethernet {{ vm_macaddress }}; if exists user-class and option user-class = "iPXE" { filename "http://${next-server}:80/.boot/boot_{{ vm_macaddress }}.ipxe";} else { filename "undionly.kpxe"; }}'
- name: Remove config files
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop:
- "{{ path_ipxe_boot }}/boot_{{ vm_macaddress }}.ipxe"
- "{{ path_preseed }}/preseed_{{ vm_macaddress }}.cfg"

View File

@ -0,0 +1,25 @@
---
#- name: Debug
# import_tasks: vm_debug.yml
# tags:
# - always
- name: Create new VM
import_tasks: vm_create.yml
- name: Config add for iPXE and DHCP
import_tasks: conf_add_ipxesrv.yml
- name: Deplay OS
import_tasks: vm_deploy_os.yml
- name: Config del for iPXE and DHCP
import_tasks: conf_del_ipxesrv.yml
- name: Custom VMs
import_tasks: vm_custom.yml

View File

@ -0,0 +1,53 @@
---
- name: Create a VM
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: "{{ vcenter_validate_certs }}"
datacenter: "{{ vcenter_datacenter }}"
folder: "{{ vm_folder }}"
name: "{{ vm_name }}"
state: poweredon
guest_id: "{{ vm_guest_id }}"
datastore: "{{ vm_datastore }}"
disk:
- size_gb: 4
type: thin
datastore: " {{ vm_datastore }}"
hardware:
memory_mb: 1024
num_cpus: 1
networks:
- name: "{{ ipxe_net_name }}"
device_type: vmxnet3
delegate_to: localhost
register: gather_create_vm
- name: Set facts vm_macaddress
set_fact:
vm_macaddress: "{{ gather_create_vm.instance.hw_eth0.macaddress }}"
delegation: localhost
- name: Set facts vm iface num
set_fact:
vm_iface_num: "{{ gather_create_vm.instance.advanced_settings['ethernet0.pciSlotNumber'] }}"
delegation: localhost
- name: Set facts vm_name_shot
set_fact:
vm_name_shot: "{{ vm_name.split('.')[0] }}"
delegation: localhost
#debug#- name: Debug
#debug# debug:
#debug# msg: "{{ gather_create_vm }}"
#debug#- name: Debug
#debug# debug:
#debug# msg: "ens + {{ vm_iface_num }} // {{ vm_macaddress }}"

View File

@ -0,0 +1,15 @@
---
- name: Custom VMs
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: "{{ vcenter_validate_certs }}"
datacenter: "{{ vcenter_datacenter }}"
folder: "{{ vm_folder }}"
name: "{{ vm_name }}"
networks:
- name: "{{ vm_net_name }}"
delegate_to: localhost
register: gather_create_vm

View File

@ -0,0 +1,7 @@
---
- name: Debug
debug:
msg: '{{ vm_name | regex_replace("\..*","") }}'

View File

@ -0,0 +1,13 @@
---
- name: Wait for VMware tools to become available
community.vmware.vmware_guest_tools_wait:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: "{{ vcenter_validate_certs }}"
datacenter: "{{ vcenter_datacenter }}"
folder: "{{ vm_folder }}"
name: "{{ vm_name }}"
timeout: 600
delegate_to: localhost
register: gather_guest_vm

View File

@ -0,0 +1,5 @@
#!ipxe
kernel http://${next-server}/.images/netinst_deb12x64/linux ipv6.disable=1 auto=true netcfg/dhcp_timeout=30 priority=critical locale=en_US preseed/url=http://${next-server}/.preseeds/preseed_{{ vm_macaddress }}.cfg
initrd http://${next-server}/.images/netinst_deb12x64/initrd.gz
boot

View File

@ -0,0 +1,141 @@
# Language and Locale
d-i debian-installer/language string en
d-i debian-installer/country string RU
d-i debian-installer/locale string en_US.UTF-8
# Hostname
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain
# Keyboard
d-i keymap select us
d-i console-keymaps-at/keymap select us
d-i keyboard-configuration/xkb-keymap select us
# Timezone / Time
d-i time/zone string Europe/Moscow
d-i clock-setup/utc boolean true
# Package Configuration
d-i pkgsel/upgrade select full-upgrade
#d-i mirror/country string TR
d-i mirror/country string manual
d-i mirror/http/hostname string reposrv.lab.loc
d-i mirror/http/directory string /debian
d-i apt-setup/services-select multiselect security, updates
d-i apt-setup/security_host string reposrv.lab.loc
d-i apt-setup/non-free boolean true
d-i apt-setup/contrib boolean true
tasksel tasksel/first multiselect none
d-i pkgsel/include string openssh-server open-vm-tools perl-modules-* net-tools mc htop bash-completion iotop iftop bwm-ng sysstat iptraf-ng iperf3 ethtool tcpdump scsitools lsscsi kpartx toilet figlet git apt-transport-https sysfsutils curl ethtool secure-delete dnsutils net-tools rpm2cpio dos2unix telnet rsync sudo whois pv screen lsof tmux hping3 nload parted netcat-openbsd wget vim rsyslog iptables man
d-i pkgsel/install-language-support boolean false
popularity-contest popularity-contest/participate boolean false
# Partitioning
d-i partman/mount_style select uuid
d-i partman-auto/disk string /dev/sda
d-i partman-basicfilesystems/choose_label string gpt
d-i partman-basicfilesystems/default_label string gpt
d-i partman-partitioning/choose_label string gpt
d-i partman-partitioning/default_label string gpt
d-i partman/choose_label string gpt
d-i partman/default_label string gpt
d-i partman-auto/method string lvm
d-i partman-auto/purge_lvm_from_device boolean true
d-i partman-auto/choose_recipe select gpt-boot-lvm
d-i partman-auto-lvm/new_vg_name string vg01
d-i partman-auto/expert_recipe string \
gpt-boot-lvm :: \
1 1 1 free \
$bios_boot{ } \
method{ biosgrub } \
. \
537 537 537 linux-swap \
$defaultignore{ } \
$lvmok{ } \
lv_name{ swap } \
method{ swap } \
format{ } \
. \
2600 2600 -1 ext4 \
$defaultignore{ } \
$lvmok{ } \
lv_name{ root } \
method{ format } \
format{ } \
use_filesystem{ } \
filesystem{ ext4 } \
mountpoint{ / } \
.
d-i partman-auto-lvm/no_boot boolean true
d-i partman/confirm boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-lvm/confirm boolean true
d-i partman/choose_partition select Finish partitioning and write changes to disk
d-i partman/confirm_nooverwrite boolean true
d-i partman/mount_style select uuid
# mkpasswd -s -m sha-512
#
d-i passwd/root-login boolean true
d-i passwd/root-password-crypted password $6$vWJHdzEQUi4x9.cd$usa.oXjqhviC1bAi4vc95o0B17LVMekzn/P5C8Q2JyFWNQj3cfntd7YzcRiNAFUCH4i4F8Y0nOS/j66rAvxov1
d-i passwd/make-user boolean false
#d-i passwd/user-fullname string user
#d-i passwd/username string user
#d-i passwd/user-password-crypted password $6$Xdo2ihdwRlBgvpQB$wPZTb9IvmjE8Y5XHsgT/OL.dPaWhna5EzLFgfWXjQ3k5NnLJqzCnb/mKBzkGQpcjSLhQCXyXqOZ0ji5E.Mu1c/
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false
d-i grub-installer/bootdev string /dev/sda
d-i debian-installer/splash boolean false
d-i finish-install/reboot_in_progress note
d-i preseed/late_command string in-target /bin/sh -c "cd /root;curl http://10.8.221.2/.preseeds/files_common/skel/.bashrc > .bashrc;cd /root;mkdir .config;mkdir ./.config/mc;chmod -R 700 .config;cd /root/.config/mc;curl http://10.8.221.2/.preseeds/files_common/mc/ini > ini;curl http://10.8.221.2/.preseeds/files_common/mc/panels.ini > panels.ini"; \
in-target /bin/sh -c "sed -i 's/^#PermitRootLogin prohibit-password/#PermitRootLogin prohibit-password\nPermitRootLogin yes/' /etc/ssh/sshd_config; sed -i 's/^PermitRootLogin without-password/#PermitRootLogin without-password\nPermitRootLogin yes/' /etc/ssh/sshd_config"; \
in-target /bin/sh -c "echo '#!/bin/bash' > /etc/update-motd.d/99-custom"; \
in-target /bin/sh -c "echo \"echo; hostname -f | sed 's/.*/\U&/' | sed 's/^/=> /' | sed 's/$/ <=/' | toilet -f term -F border --gay\" >> /etc/update-motd.d/99-custom"; \
in-target chmod 755 /etc/update-motd.d/99-custom; \
in-target mkdir -p /root/.ssh; \
in-target /bin/sh -c "echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDrHbdpfwqnQdPXnpX70Bq8Msq7bcLUuTRWT/JqwTtbEBDEvJCjNUJiJlefqrAFP58qew2u826olTuRqfDhb/lsBPUFUzU63aWmEAdhITTsYQYof9o2FKzDwK/qc1Bz17UELWlruNHdTjciz6BV+9ZLqNwmQ1CXO2rSt5D57Bv13LRtlTZ1LOIvA3HGr0NmCjr+FmHvihNqinSkqfdfd6SMMqwYEFvHscH2bazGZorqKwHc7q7INOSsU5JPlX2SbcstcMclocAWmX+DdbylZRtuEVky4vZqmGJjPQ3w5Ng5nLa1BEIDk3Hc7vW5BJsCM8mqTmmgWVnZHpakAOaFvjgcevKTr7fEyELzbOO42MUu29HjMP24VZnpdQJxc1zZ9UXCGW1Rd0b3hll8SAbYBBOeYNt+yGR8j8uPeP9sHhuEIRgMwKgHSVTF5ZaeqUneQcawrRGLg5++nyze/wMqCLYCSUykxxZYuhCk1cxPlGoXNokGWkQDinm+IlG9AxKI6C72qGhSZTBZPkD7qlY+HftnZHa8RGh0mc8ANhxOcXbZzBBaSHm7Dbf/Nc/0T58V1DJnwUmY3Y87E9rvkiN+PhSxzNgLfPeNtJHVyvA76ONEgieOIPU288nkKHDIwNhzb3fS6BajMq05ZgP49qsaLfcUTlYfHgkuWXjfne9ADNSsJw== root@local.local' >> /root/.ssh/authorized_keys"; \
in-target chown -R root:root /root/.ssh; \
in-target chmod 600 /root/.ssh/authorized_keys; \
in-target chmod 700 /root/.ssh; \
in-target sed -i 's/quiet/quiet ipv6.disable=1/' /etc/default/grub; \
in-target /bin/sh -c "update-grub"; \
in-target /bin/sh -c "curl http://10.8.221.2/.preseeds/scripts_common/rc.local > /etc/rc.local; curl http://10.8.221.2/.preseeds/scripts_common/first_start.sh > /root/first_start.sh"; \
in-target chmod 755 /etc/rc.local; \
in-target chmod 755 /root/first_start.sh; \
in-target /bin/sh -c "update-alternatives --set iptables /usr/sbin/iptables-legacy"; \
in-target /bin/sh -c "echo > /etc/network/interfaces"; \
in-target /bin/sh -c "echo 'source /etc/network/interfaces.d/*' >> /etc/network/interfaces"; \
in-target /bin/sh -c "echo >> /etc/network/interfaces"; \
in-target /bin/sh -c "echo 'auto lo' >> /etc/network/interfaces"; \
in-target /bin/sh -c "echo 'iface lo inet loopback' >> /etc/network/interfaces"; \
in-target /bin/sh -c "echo >> /etc/network/interfaces"; \
in-target /bin/sh -c "echo 'auto ens{{ vm_iface_num }}' >> /etc/network/interfaces"; \
in-target /bin/sh -c "echo 'allow-hotplug ens{{ vm_iface_num }}' >> /etc/network/interfaces"; \
in-target /bin/sh -c "echo ' iface ens{{ vm_iface_num }} inet static' >> /etc/network/interfaces"; \
in-target /bin/sh -c "echo ' address {{ vm_ip_addr }}' >> /etc/network/interfaces"; \
in-target /bin/sh -c "echo ' netmask {{ vm_ip_mask }}' >> /etc/network/interfaces"; \
in-target /bin/sh -c "echo ' gateway {{ vm_ip_gw }}' >> /etc/network/interfaces"; \
in-target /bin/sh -c "echo '{{ vm_name }}' > /etc/hostname"; \
in-target /bin/sh -c "echo '127.0.0.1 localhost' > /etc/hosts"; \
in-target /bin/sh -c "echo '{{ vm_ip_addr }} {{ vm_name }} {{ vm_name_shot }}' >> /etc/hosts"; \
in-target /bin/sh -c "echo >> /etc/hosts"; \
in-target /bin/sh -c "echo '# The following lines are desirable for IPv6 capable hosts' >> /etc/hosts"; \
in-target /bin/sh -c "echo '::1 localhost ip6-localhost ip6-loopback' >> /etc/hosts"; \
in-target /bin/sh -c "echo 'ff02::1 ip6-allnodes' >> /etc/hosts"; \
in-target /bin/sh -c "echo 'ff02::2 ip6-allrouters' >> /etc/hosts"; \
in-target /bin/sh -c "echo 'domain {{ vm_ip_domain }}' > /etc/resolv.conf"; \
in-target /bin/sh -c "echo 'search {{ vm_ip_search }}' >> /etc/resolv.conf"; \
in-target /bin/sh -c "echo 'nameserver {{ vm_ip_dns }}' >> /etc/resolv.conf"

View File

@ -0,0 +1,5 @@
---
path_ipxe_boot: "/var/www/html/.boot"
path_dhcp_conf: "/etc/dhcp/dhcpd_tmp.conf"
path_preseed: "/var/www/html/.preseeds"