mirror of
https://github.com/khuedoan/homelab.git
synced 2025-01-22 02:07:46 +07:00
feat: generate dev VM IP address based on inventory
This commit is contained in:
parent
66c70c023f
commit
6f0f8dd6f9
1
metal/.gitignore
vendored
1
metal/.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
host_vars/dev*.yml
|
|
53
metal/Vagrantfile
vendored
53
metal/Vagrantfile
vendored
@ -1,47 +1,42 @@
|
|||||||
# require 'ipaddr' # TODO dynamic IP based on inventory OR dynamic inventory
|
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
|
|
||||||
ip_prefix = '192.168.1.' # TODO see above
|
inventory = YAML.load_file(File.join(__dir__, './inventories/dev.yml'))
|
||||||
group_vars = YAML.load_file(File.join(__dir__, './group_vars/all.yml'))
|
group_vars = YAML.load_file(File.join(__dir__, './group_vars/all.yml'))
|
||||||
|
|
||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
config.vm.box = "rockylinux/8"
|
config.vm.box = "rockylinux/8"
|
||||||
|
|
||||||
node_count = 1
|
inventory['metal']['children'].each do |group, properties|
|
||||||
|
properties['hosts'].each do |host, host_vars|
|
||||||
# TODO clean up
|
config.vm.define host do |node|
|
||||||
# - support multiple nodes
|
ip = host_vars['ansible_host']
|
||||||
# - generate inventory dynamically https://www.simonholywell.com/post/2016/02/intelligent-vagrant-and-ansible-files/
|
node.vm.network "private_network", ip: ip
|
||||||
Dir.mkdir(File.join(__dir__, './host_vars')) unless Dir.exist?(File.join(__dir__, './host_vars'))
|
node.vm.hostname = host
|
||||||
|
node.vm.disk :disk, size: "256GB", primary: true
|
||||||
(0..(node_count-1)).each do |i|
|
|
||||||
config.vm.define "dev#{i}" do |dev|
|
|
||||||
dev.vm.network "public_network", ip: "#{ip_prefix}#{200+i+1}"
|
|
||||||
dev.vm.hostname = "dev#{i}"
|
|
||||||
dev.vm.disk :disk, size: "256GB", primary: true
|
|
||||||
|
|
||||||
File.open("#{File.join(__dir__, './host_vars')}/dev#{i}.yml" ,'w') do |f|
|
|
||||||
f.write "ansible_host: #{ip_prefix}#{200+i+1}"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
config.vm.provider "virtualbox" do |vb|
|
config.vm.provider "virtualbox" do |vb|
|
||||||
# TODO this is ridiculous for a dev VM, optimize it
|
# TODO this is ridiculous for a local environment, optimize it
|
||||||
vb.cpus = 6
|
vb.cpus = 6
|
||||||
vb.memory = "10240"
|
vb.memory = "10240"
|
||||||
end
|
end
|
||||||
|
|
||||||
config.vm.provision "file", source: "#{group_vars['ansible_ssh_private_key_file']}.pub", destination: "/tmp/id_ed25519.pub"
|
config.vm.provision "file",
|
||||||
|
source: "#{group_vars['ansible_ssh_private_key_file']}.pub",
|
||||||
|
destination: "/tmp/id_ed25519.pub"
|
||||||
|
|
||||||
# TODO move part of this to Ansible?
|
# TODO move most of this to Ansible?
|
||||||
config.vm.provision "shell", inline: <<-SHELL
|
config.vm.provision "shell",
|
||||||
mkdir /#{group_vars['ansible_user']}/.ssh
|
reboot: true,
|
||||||
cat /tmp/id_ed25519.pub >> /#{group_vars['ansible_user']}/.ssh/authorized_keys
|
inline: <<-SHELL
|
||||||
setenforce Permissive
|
mkdir /#{group_vars['ansible_user']}/.ssh
|
||||||
dnf install -y iscsi-initiator-utils
|
cat /tmp/id_ed25519.pub >> ~#{group_vars['ansible_user']}/.ssh/authorized_keys
|
||||||
systemctl enable --now iscsid
|
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
|
||||||
sysctl fs.inotify.max_user_instances=8192
|
dnf install -y iscsi-initiator-utils
|
||||||
sysctl -p
|
systemctl enable --now iscsid
|
||||||
SHELL
|
sysctl fs.inotify.max_user_instances=8192
|
||||||
|
sysctl -p
|
||||||
|
SHELL
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
|
# TODO support multiple nodes (doesn't work yet)
|
||||||
metal:
|
metal:
|
||||||
children:
|
children:
|
||||||
masters:
|
masters:
|
||||||
hosts:
|
hosts:
|
||||||
dev0: {ansible_host: 192.168.56.10}
|
dev0: {ansible_host: 192.168.56.10}
|
||||||
|
# dev1: {ansible_host: 192.168.56.11}
|
||||||
|
# dev2: {ansible_host: 192.168.56.12}
|
||||||
|
workers:
|
||||||
|
hosts: {}
|
||||||
|
# dev3: {ansible_host: 192.168.56.13}
|
||||||
|
Loading…
Reference in New Issue
Block a user