WIP
This commit is contained in:
59
buildvm.yml
59
buildvm.yml
@@ -1,7 +1,54 @@
|
||||
# Playbook to build new VMs in RHV Cluster
|
||||
# Currently only builds RHEL VMs
|
||||
|
||||
# Create Host
|
||||
|
||||
- name: Preflight checks
|
||||
hosts: tag_build
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- assert:
|
||||
that:
|
||||
- site == "sagely_dc"
|
||||
- is_virtual
|
||||
|
||||
- name: Ensure Primary IP exists and is in DNS
|
||||
hosts: tag_build
|
||||
gather_facts: false
|
||||
|
||||
tasks:
|
||||
- name: Get unused IP Address from pool
|
||||
netbox.netbox.netbox_ip_address:
|
||||
netbox_url: "{{ netbox_api }}"
|
||||
netbox_token: "{{ netbox_token }}"
|
||||
data:
|
||||
prefix: 192.168.16.0/20
|
||||
state: new
|
||||
register: new_ip
|
||||
when: primary_ipv4 is undefined
|
||||
delegate_to: localhost
|
||||
|
||||
- set_fact:
|
||||
primary_ipv4: "{{ new_ip.ip_address.address|ipaddr('address') }}"
|
||||
vm_hostname: "{{ inventory_hostname.split('.')[0] }}"
|
||||
vm_domain: "{{ inventory_hostname.split('.',1)[1] }}"
|
||||
delegate_to: localhost
|
||||
when: primary_ipv4 is undefined
|
||||
|
||||
- name: Ensure IP Address in IdM
|
||||
freeipa.ansible_freeipa.ipadnsrecord:
|
||||
records:
|
||||
- name: "{{ vm_hostname }}"
|
||||
zone_name: "{{ vm_domain }}"
|
||||
record_type: A
|
||||
record_value:
|
||||
- "{{ new_ip.ip_address.address|ipaddr('address') }}"
|
||||
create_reverse: true
|
||||
ipaadmin_password: "{{ ipaadmin_password }}"
|
||||
delegate_to: idm1.mgmt.toal.ca
|
||||
|
||||
- name: Create VMs
|
||||
hosts: cluster_ToalLabRHV
|
||||
hosts: tag_build
|
||||
connection: local
|
||||
gather_facts: no
|
||||
collections:
|
||||
@@ -10,10 +57,6 @@
|
||||
# Workaround to get correct venv python interpreter
|
||||
ansible_python_interpreter: "{{ ansible_playbook_python }}"
|
||||
|
||||
# Never run this, unless specifically enabled
|
||||
# tags:
|
||||
# - never
|
||||
# - rebuild
|
||||
|
||||
tasks:
|
||||
- name: Basic Disk Profile
|
||||
@@ -60,7 +103,7 @@
|
||||
disks: '{{ vm_disks }}'
|
||||
cpu_cores: '{{ vcpus }}'
|
||||
cluster: '{{ cluster }}'
|
||||
# Damn... This is ugly
|
||||
# This is ugly Can we do better?
|
||||
operating_system: '{{ query("netbox.netbox.nb_lookup", "platforms", api_filter=nb_query_filter, api_endpoint=netbox_api, token=netbox_token)[0].value.name }}'
|
||||
type: server
|
||||
graphical_console:
|
||||
@@ -96,7 +139,7 @@
|
||||
register: vm_build_result
|
||||
|
||||
- name: Ensure VM is running and reachable
|
||||
hosts: cluster_ToalLabRHV
|
||||
hosts: tag_build
|
||||
gather_facts: no
|
||||
connection: local
|
||||
vars:
|
||||
@@ -116,3 +159,5 @@
|
||||
wait_for_connection:
|
||||
timeout: 1800
|
||||
sleep: 5
|
||||
|
||||
#TODO: Clear Build tag
|
||||
@@ -5,3 +5,9 @@ collections:
|
||||
|
||||
- name: netbox.netbox
|
||||
source: https://galaxy.ansible.com
|
||||
|
||||
- name: freeipa.ansible_freeipa
|
||||
source: https://galaxy.ansible.com
|
||||
|
||||
- name: ovirt.ovirt
|
||||
source: https://galaxy.ansible.com
|
||||
|
||||
33
create_host.yml
Normal file
33
create_host.yml
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
# Create Host
|
||||
- name: Get IP Address from pool
|
||||
hosts: localhost
|
||||
|
||||
tasks:
|
||||
- name: Get unused IP Address from pool
|
||||
netbox.netbox.netbox_ip_address:
|
||||
netbox_url: "{{ netbox_api }}"
|
||||
netbox_token: "{{ netbox_token }}"
|
||||
data:
|
||||
prefix: 192.168.16.0/20
|
||||
state: new
|
||||
register: new_ip
|
||||
|
||||
- debug: var=new_ip
|
||||
|
||||
- name: Create IP Address in IdM
|
||||
freeipa.ansible_freeipa.ipadnsrecord:
|
||||
records:
|
||||
- name: test1
|
||||
zone_name: sandbox.toal.ca
|
||||
record_type: A
|
||||
record_value:
|
||||
- "{{ new_ip.ip_address.address|ipaddr('address') }}"
|
||||
create_reverse: true
|
||||
ipaadmin_password: "{{ ipaadmin_password }}"
|
||||
delegate_to: idm1.mgmt.toal.ca
|
||||
|
||||
|
||||
# - name: Create Satellite Host
|
||||
# - name: Create RHV VM
|
||||
# - name:
|
||||
24
create_satellite_host.yml
Normal file
24
create_satellite_host.yml
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
- name: Create new VM / Host in Satellite
|
||||
hosts: sat6.lab.toal.ca
|
||||
vars:
|
||||
sat6_fqdn: "sat6.lab.toal.ca"
|
||||
#sat6_pass: "this is set in the secrets file"
|
||||
sat6_organization: "Toal.ca"
|
||||
sat6_fail_on_existing: True
|
||||
sat6_power_on_delay: 60
|
||||
sat6_hosts:
|
||||
#VM
|
||||
- name: "rhel1"
|
||||
host_group: "Lab RHEL Hosts/RHEL 8"
|
||||
location: "Lab"
|
||||
ipv4: "192.168.16.10"
|
||||
domain: "sandbox.toal.ca"
|
||||
comment: "Demo Server"
|
||||
compute_resource: "Home Lab"
|
||||
compute_profile: "2-Medium"
|
||||
parameters:
|
||||
- name: "build_type"
|
||||
value: "httpd"
|
||||
roles:
|
||||
- ahuffman.sat6_create_hosts
|
||||
25
pimgmt.yml
25
pimgmt.yml
@@ -1,25 +0,0 @@
|
||||
---
|
||||
# Configure a Raspberry Pi running Fedora 32+ for Management functions.
|
||||
|
||||
|
||||
# - name: Set Up DHCP System
|
||||
# hosts: dhcp-server
|
||||
# become: true
|
||||
|
||||
# tasks:
|
||||
# - name: DHCP Daemon is installed
|
||||
# apt:
|
||||
# name: isc-dhcp-server
|
||||
# state: latest
|
||||
# notify: Restart DHCPD
|
||||
|
||||
# - name: Generate dhcpd.conf
|
||||
# template:
|
||||
# src: dhcpd.conf.j2
|
||||
# dest: "{{ dhcpd_conf_path }}"
|
||||
|
||||
# handlers:
|
||||
# - name: Restart DHCPD
|
||||
# service:
|
||||
# name: isc-dhcpd-server
|
||||
# state: restarted
|
||||
47
site.yml
47
site.yml
@@ -1,18 +1,12 @@
|
||||
# Toal Lab Site Playbook
|
||||
- name: Set up Network interfaces
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
become: true
|
||||
|
||||
roles:
|
||||
- name: linux-system-roles.network
|
||||
when: network_connections is defined
|
||||
|
||||
- name: Common Lab Machine Setup
|
||||
hosts: platform_linux,platform_fedora_linux
|
||||
become: true
|
||||
roles:
|
||||
- toal-common
|
||||
|
||||
- name: linux-system-roles.network
|
||||
when: network_connections is defined
|
||||
- name: toal-common
|
||||
|
||||
- name: Set Network OS from Netbox info.
|
||||
gather_facts: no
|
||||
@@ -31,11 +25,40 @@
|
||||
roles:
|
||||
- toallab.infrastructure
|
||||
|
||||
- name: DHCP Server
|
||||
hosts: service_dhcp
|
||||
become: yes
|
||||
|
||||
pre_tasks:
|
||||
# - name: Gather interfaces for dhcp service
|
||||
# set_fact:
|
||||
# dhcp_interfaces:
|
||||
# - name: Gather subnets
|
||||
# set_fact:
|
||||
# subnets: ""
|
||||
# prefixes: "{{ query('netbox.netbox.nb_lookup', 'prefixes', api_endpoint=netbox_api, token=netbox_token) }}"
|
||||
|
||||
# - ip: 192.168.222.0
|
||||
# netmask: 255.255.255.128
|
||||
# domain_name_servers:
|
||||
# - 10.0.2.3
|
||||
# - 10.0.2.4
|
||||
# range_begin: 192.168.222.50
|
||||
# range_end: 192.168.222.127
|
||||
# - ip: 192.168.222.128
|
||||
# default_lease_time: 3600
|
||||
# max_lease_time: 7200
|
||||
# netmask: 255.255.255.128
|
||||
# domain_name_servers: 10.0.2.3
|
||||
# routers: 192.168.222.129
|
||||
roles:
|
||||
- name: sage905.netbox-to-dhcp
|
||||
|
||||
- name: Include Minecraft tasks
|
||||
import_playbook: minecraft.yml
|
||||
|
||||
- name: Include Gitea tasks
|
||||
import_playbook: gitea.yml
|
||||
# - name: Include Gitea tasks
|
||||
# import_playbook: gitea.yml
|
||||
|
||||
# - name: Include Pod Host
|
||||
# include: podhost.yml
|
||||
|
||||
45
t.yml
Normal file
45
t.yml
Normal file
@@ -0,0 +1,45 @@
|
||||
---
|
||||
- name: DHCP Server
|
||||
hosts: service_dhcp
|
||||
connection: local
|
||||
|
||||
pre_tasks:
|
||||
# - name: Gather interfaces for dhcp service
|
||||
# set_fact:
|
||||
# dhcp_interfaces:
|
||||
# - name: Gather subnets
|
||||
# set_fact:
|
||||
# subnets: ""
|
||||
# prefixes: "{{ query('netbox.netbox.nb_lookup', 'prefixes', api_endpoint=netbox_api, token=netbox_token) }}"
|
||||
|
||||
# - ip: 192.168.222.0
|
||||
# netmask: 255.255.255.128
|
||||
# domain_name_servers:
|
||||
# - 10.0.2.3
|
||||
# - 10.0.2.4
|
||||
# range_begin: 192.168.222.50
|
||||
# range_end: 192.168.222.127
|
||||
# - ip: 192.168.222.128
|
||||
# default_lease_time: 3600
|
||||
# max_lease_time: 7200
|
||||
# netmask: 255.255.255.128
|
||||
# domain_name_servers: 10.0.2.3
|
||||
# routers: 192.168.222.129
|
||||
roles:
|
||||
- name: sage905.netbox-to-dhcp
|
||||
|
||||
# tasks:
|
||||
# - debug:
|
||||
# var: services
|
||||
|
||||
# # - name: Collect Prefix information for interfaces in DHCP Service
|
||||
|
||||
# - name: Collect host interfaces
|
||||
# set_fact:
|
||||
# dhcp_prefixes: "{{ query('netbox.netbox.nb_lookup', 'prefixes', api_filter='', api_endpoint=netbox_api, token=netbox_token) }}"
|
||||
|
||||
# - name: Test
|
||||
# debug: var=dhcp_service
|
||||
{% for interface in (services|selectattr('name','eq','dhcp')|first).ipaddresses %}
|
||||
{% set prefix=(query('netbox.netbox.nb_lookup', 'prefixes', api_filter='q=' + interface.address, api_endpoint=netbox_api, token=netbox_token)|first).value %}
|
||||
subnet {{ prefix.prefix|ipaddr('net') }} netmask {{ prefix.prefix|ipaddr('netmask') }} {
|
||||
Reference in New Issue
Block a user