Skip to content

Instantly share code, notes, and snippets.

@hbokh
Last active March 19, 2017 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hbokh/a31d47ff1a3f6a03c284f45ef02a704f to your computer and use it in GitHub Desktop.
Save hbokh/a31d47ff1a3f6a03c284f45ef02a704f to your computer and use it in GitHub Desktop.
Terraform-file to add five systems within Cobbler.
provider "cobbler" {
username = "${var.cobbler_username}"
password = "${var.cobbler_password}"
url = "${var.cobbler_url}"
}
####[ NOTE ]##########################################
# Dir /var/www is used by Cobbler on CentOS / Red Hat.
# Cobbler on Debian uses /srv/www instead.
######################################################
/*resource "cobbler_distro" "debian8" {
name = "debian8"
breed = "debian"
os_version = "jessie"
arch = "x86_64"
kernel = "/var/www/cobbler/ks_mirror/debian8-x86_64/install.amd/vmlinuz"
initrd = "/var/www/cobbler/ks_mirror/debian8-x86_64/install.amd/initrd.gz"
}
resource "cobbler_profile" "debian-jessie" {
name = "debian-jessie"
distro = "debian8"
kickstart = "/var/lib/cobbler/kickstarts/debian8-virtual.seed"
ks_meta = "release=8"
kernel_options = "ipv6.disable=1"
name_servers = ["192.168.0.3", "8.8.8.8"] # Should be a list
name_servers_search = ["internal"]
repos = ["debian8-x86_64"]
}*/
resource "cobbler_system" "server" {
count = "5"
name = "linux01${count.index}"
profile = "debian8-x86_64"
hostname = "linux01${count.index}"
gateway = "192.168.0.1"
kickstart = "/var/lib/cobbler/kickstarts/debian8-virtual.seed"
ks_meta = "fs=xfs machinetype=vmware"
status = "testing"
netboot_enabled = "1"
virt_type = "vmware"
power_type = "vmware_soap"
interface {
name = "eth0"
mac_address = "00:de:ad:00:00:5${count.index}"
ip_address = "192.168.0.15${count.index}"
netmask = "255.255.255.0"
gateway = "192.168.0.1"
management = true # Not working...
dns_name = "linux01${count.index}.internal"
static = true
}
}
resource "cobbler_snippet" "partitioning" {
name = "/var/lib/cobbler/snippets/partitioning"
body = <<EOF
#if $machinetype == 'kvm'
#set $disk='vda'
#else if $machinetype == 'xen'
#set $disk = 'xvda'
#else
#set $disk = 'sda'
#end if
d-i partman-auto/select_disk string /dev/$disk
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto-lvm/guided_size string max
d-i partman-auto/expert_recipe string \
boot-root :: \
512 1000 512 ext4 \
$primary{ } $bootable{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext4 } \
mountpoint{ /boot } \
. \
100 10000 1000000000 $fs \
method{ lvm } \
use_filesystem{ } \
format{ } \
vg_name{ rootVG } \
. \
4096 2000 4096 $fs \
$lvmok{ } \
method{ format } format{ } \
in_vg{ rootVG } \
lv_name{ root } \
use_filesystem{ } filesystem{ $fs } \
mountpoint{ / } \
. \
1024 1000 1024 $fs \
$lvmok{ } \
method{ format } format{ } \
in_vg{ rootVG } \
lv_name{ home } \
use_filesystem{ } filesystem{ $fs } \
mountpoint{ /home } \
. \
512 1000 512 $fs \
$lvmok{ } \
method{ format } format{ } \
in_vg{ rootVG } \
lv_name{ tmp } \
use_filesystem{ } filesystem{ $fs } \
mountpoint{ /tmp } \
. \
1024 1000 1024 linux-swap \
$lvmok{ } \
method{ swap } format{ } \
in_vg{ rootVG } \
lv_name{ swap } \
. \
100 1000 1000000000 $fs \
$lvmok{ } \
method{ format } format{ } \
in_vg{ rootVG } \
lv_name{ var } \
use_filesystem{ } filesystem{ $fs } \
mountpoint{ /var } \
.
d-i partman/default_filesystem string $fs
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman-partitioning/unknown_label boolean true
d-i partman-partitioning/confirm_new_label boolean true
d-i partman-partitioning/confirm_write_new_label boolean true
EOF
}
resource "cobbler_kickstart_file" "debian8-virtual" {
name = "/var/lib/cobbler/kickstarts/debian8-virtual.seed"
body = <<EOF
#### Contents of the preconfiguration file
### Localization
d-i debian-installer/language string en
d-i debian-installer/country string NL
d-i debian-installer/locale select en_US.UTF-8
--- cut --- 8< ---
## Figure out if we're kickstarting a system or a profile
#if $getVar('system_name','') != ''
#set $what = "system"
#else
#set $what = "profile"
#end if
### Finishing up the installation
d-i finish-install/reboot_in_progress note
d-i preseed/late_command string wget -O- \
http://$http_server/cblr/svc/op/script/$what/$name/?script=preseed_late_default | \
chroot /target /bin/sh -s
EOF
}
cobbler_username = "cobbler"
cobbler_password = "p4ssw0rd"
cobbler_url = "http://cobbler.internal/cobbler_api"
variable "cobbler_username" {
description = "Cobbler admin user"
default = "some_user"
}
variable "cobbler_password" {
description = "Password for the Cobbler admin"
default = "some_password"
}
variable "cobbler_url" {
description = "Where to reach the Cobbler API"
default = "http://some_server/cobbler_api"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment