Skip to content

Instantly share code, notes, and snippets.

@ravibhure
Created January 15, 2014 05:25
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 ravibhure/8431279 to your computer and use it in GitHub Desktop.
Save ravibhure/8431279 to your computer and use it in GitHub Desktop.
#!/bin/bash
# basic cobbler setup, just to give some idea of the commands you will need to run...
cobbler-ubuntu-import precise-x86_64
# FIXME: need to template out various things
profile_kopts="ksdevice=bootif locale=en_US text netcfg/confirm_static=true netcfg/get_gateway=2.2.1.1 priority=critical netcfg/get_nameservers=2.2.1.254 netcfg/disable_autoconfig=true netcfg/dhcp_options='Configure network manually' netcfg/no_default_route=true netcfg/choose_interface=auto partman-auto/disk=/dev/sda netcfg/get_netmask=255.255.255.0 netcfg/dhcp_failed=true"
echo "profile options = $profile_kopts"
cmd="cobbler profile add --name=openstack --distro=precise-x86_64 --kickstart=/etc/cobbler/preseeds/cisco-preseed --kopts=\"${profile_kopts}\" --clobber"
eval $cmd
# just adding for DNS, it cannot reinstall itself
cmd=<< EOM
cobbler system add --name=cvf2-server-b1 \
--mac-address=90:e2:ba:0d:28:08 \
--ip-address=2.2.1.254 \
--dns-name=cvf2-server-b1.local.lab \
--profile=openstack \
--power-type=ipmitool \
--power-user=administrator \
--power-pass=password \
--power-address=cvf2-server-b1-cimc.cisco.com \
--netboot-enabled=0
--kopts='netcfg/get_ipaddress=2.6.1.254' \
--clobber
EOM
eval $cmd
cmd=<< EOM
cobbler system add --name=control01 \
--mac-address=90:e2:ba:0f:6c:ec \
--ip-address=2.2.1.2 \
--dns-name=control01.local.lab \
--profile=openstack \
--power-type=ipmitool \
--power-user=admin \
--power-pass=password \
--power-address=cvf2-server-b2-cimc.cisco.com \
--netboot-enabled=0 \
--kopts='netcfg/get_ipaddress=2.2.1.2' \
--clobber
EOM
eval $cmd
cobbler sync
---
- name: cobbler installation
apt: name=$item state=present
with_items:
- dnsmasq
- tftpd-hpa
- cobbler
- apt-cacher-ng
notify:
- restart apache2
- name: preseed setup
template: src=./cobbler/templates/preseed.j2 dest=/etc/cobbler/preseeds/cisco-preseed
- name: apt-cacher-ng config
template: src=./cobbler/templates/acng.j2 dest=/etc/apt-cacher-ng/acng.conf
notify:
- restart apt-cacher-ng
- name: cobbler settings
template: src=./cobbler/templates/settings.j2 dest=/etc/cobbler/settings
notify:
- restart cobbler
- name: cobbler modules.conf
template: src=./cobbler/templates/modules.conf.j2 dest=/etc/cobbler/modules.conf
notify:
- restart cobbler
# TODO: ISC/bind combo not done here yet. Skipping for now.
- name: cobbler dnsmasq template
template: src=./cobbler/templates/dnsmasq.template.j2 dest=/etc/cobbler/dnsmasq.template
notify:
- restart cobbler
- name: ensure cobbler is running
service: name=cobbler state=running enabled=yes
- name: ensure apache is running
service: name=apache2 state=running enabled=yes
- name: ensure apt-cacher-ng is running
service: name=apt-cacher-ng state=running enabled=yes
# we could use the current user here, just assume administrator for now
- name: make my remote sudoers config web accessible (preseed hack)
template: src=./cobbler/templates/sudoers.j2 dest=/var/www/sudoers
- name: set up post script for the preseed
template: src=./cobbler/templates/post.j2 dest=/var/www/post.sh
# NOTE: you are expected to manage the setup of your cobbler distros and systems on
# your own for now. Resource may wrap these later.
#/bin/sh
# remove LVM hack
# setup sudoers
cat << 'SUDOERS' > /target/etc/sudoers2;
Defaults env_reset
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$"
%{{ admin_user }} ALL= NOPASSWD: ALL
SUDOERS
# setup SSH key & authorized_keys
mkdir -p /target/home/{{ admin_user }}/.ssh
/target/usr/bin/ssh-keygen -f /target/home/{{ admin_user }}/.ssh/id_rsa -C 'bad wolf' -N '' -t rsa -q
# not sure why we have quotes around this key, fix it
cat << 'PUBKEY' | cut -c 1- | cut -b 2- > /target/home/{{ admin_user }}/.ssh/authorized_keys
{{ ansible_pubkey }} PUBKEY
true
d-i mirror/country string manual
d-i mirror/http/hostname string us.archive.ubuntu.com
d-i mirror/http/directory string /ubuntu
d-i mirror/http/proxy string {{ cobbler_proxy }}
d-i partman/early_command string vgs --separator=: --noheadings | cut -f1 -d: | while read vg ; do vgchange -an $vg ; done ; pvs --separator=: --noheadings | cut -f1 -d: | while read pv ; do pvremove -ff -y $pv ; done
d-i partman-auto/disk string {% for element in diskpart %}{{ element }} {% endfor %}
d-i partman/alignment string cylinder
d-i partman-md/device_remove_md boolean true
d-i partman-md/confirm 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
d-i partman/confirm_write_new_label boolean true
{% if expert_disk %}
d-i partman-auto/method string lvm
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/choose_recipe select openstack
d-i partman-auto/expert_recipe string \
openstack :: \
1 1 1 free \
$gptonly{ } \
$primary{ } \
$bios_boot{ } \
method{ biosgrub } \
. \
200 200 200 ext3 \
$gptonly{ } \
$primary{ } \
device{ {{ boot_disk }} } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext3 } \
mountpoint{ /boot } \
. \
{% for element in diskpart %}20480 1000000 1000000000 ext4 \
$defaultignore{ } \
$gptonly{ } \
$primary{ } \
method{ lvm } \
device{ {{ element }} } \
vg_name{ nova-volumes } \
. \
{% endfor %}
10240 10240 10240 ext4 \
$lvmok{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext4 } \
mountpoint{ / } \
in_vg{ nova-volumes } \
lv_name{ slash } \
. \
4098 512 4098 linux-swap \
$lvmok{ } \
method{ swap } format{ } \
in_vg{ nova-volumes } \
lv_name{ swap } \
. \
10240 10240 102400 ext4 \
$lvmok{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext4 } \
mountpoint{ /var } \
in_vg{ nova-volumes } \
lv_name{ var } \
. \
10240 10240 102400 ext4 \
$lvmok{ } \
mountpoint{ /tmp/hack } \
in_vg{ nova-volumes } \
lv_name{ hack } \
.
{% else %}
d-i partman-auto/method string regular
d-i partman-auto/choose_recipe select atomic
{% endif %}
d-i partman/choose_partition select Finish partitioning and write changes to disk
d-i partman-md/confirm_nooverwrite boolean true
d-i partman-md/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-lvm/confirm boolean true
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select Finish
d-i partman/confirm_nooverwrite boolean true
d-i partman/confirm boolean true
d-i clock-setup/utc boolean true
{% if ntp_server %}d-i clock-setup/ntp boolean true
d-i clock-setup/ntp-server string {{ ntp_server }}{% endif %}
d-i time/zone string UTC
d-i passwd/user-fullname string Admin Adminson
d-i passwd/username string {{ admin_user }}
d-i passwd/user-password-crypted password {{ password_crypted }}
d-i user-setup/encrypt-home boolean false
d-i grub-installer/only_debian boolean true
d-i finish-install/reboot_in_progress note
d-i pkgsel/update-policy select none
d-i pkgsel/include string {{ packages }}
d-i preseed/early_command string http_proxy="" wget -O /dev/null http://$http_server:$http_port/cblr/svc/op/trig/mode/pre/system/$system_name;
d-i preseed/late_command string /sbin/lvremove -f nova-volumes/hack; http_proxy="" wget -O /dev/null http://$http_server:$http_port/cblr/svc/op/nopxe/system/$system_name; http_proxy="" wget -q -O - http://$http_server:$http_port/post.sh | sh; {{late_command }}; true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment