Added this repo
This commit is contained in:
@ -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
|
@ -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"
|
25
ansible/roles/os-ipxe-vmware-deploy/tasks/main.yml
Normal file
25
ansible/roles/os-ipxe-vmware-deploy/tasks/main.yml
Normal 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
|
||||
|
||||
|
||||
|
||||
|
53
ansible/roles/os-ipxe-vmware-deploy/tasks/vm_create.yml
Normal file
53
ansible/roles/os-ipxe-vmware-deploy/tasks/vm_create.yml
Normal 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 }}"
|
||||
|
||||
|
||||
|
||||
|
15
ansible/roles/os-ipxe-vmware-deploy/tasks/vm_custom.yml
Normal file
15
ansible/roles/os-ipxe-vmware-deploy/tasks/vm_custom.yml
Normal 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
|
7
ansible/roles/os-ipxe-vmware-deploy/tasks/vm_debug.yml
Normal file
7
ansible/roles/os-ipxe-vmware-deploy/tasks/vm_debug.yml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
|
||||
|
||||
- name: Debug
|
||||
debug:
|
||||
|
||||
msg: '{{ vm_name | regex_replace("\..*","") }}'
|
13
ansible/roles/os-ipxe-vmware-deploy/tasks/vm_deploy_os.yml
Normal file
13
ansible/roles/os-ipxe-vmware-deploy/tasks/vm_deploy_os.yml
Normal 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
|
Reference in New Issue
Block a user