Last active
February 29, 2016 10:51
-
-
Save GregSutcliffe/4f2d8d8da8fa27e452a8 to your computer and use it in GitHub Desktop.
Foreman Dev Seeds - replace : with / in the filenames to get the paths, use rake db:seed to use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file just loads all my local seeds from local-seeds.d in much the same | |
# way as the main seed loader. | |
unless ENV['NOLOCAL'] == 'true' | |
local_seeds = Dir.glob(Rails.root + 'db/seeds.d/local-seeds.d/*.rb') | |
local_seeds = local_seeds.sort do |a, b| | |
a.split('/').last <=> b.split('/').last | |
end | |
local_seeds.each do |seed| | |
puts "Seeding local-seed #{seed}" unless Rails.env.test? | |
load seed | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# My user | |
User.without_auditing do | |
User.as_anonymous_admin do | |
user = User.find_by_login('gwmngilfen') || User.new(:login => 'gwmngilfen', | |
:firstname => 'Greg', | |
:lastname => 'Sutcliffe', | |
:mail => 'greg.sutcliffe@gmail.com') | |
user.auth_source = AuthSourceInternal.find_by_type('AuthSourceInternal') | |
user.admin = true | |
user.password = 'changeme' | |
raise "Unable to create local user: #{format_errors user}" unless user.save | |
User.current = user # Local stuff should be created by the local user | |
end | |
end | |
## Taxonomies | |
# Organization.find_or_create_by_name!(:name => 'Local Organization') | |
# Location.find_or_create_by_name!(:name => 'Local Location') | |
SmartProxy.where(:name=>'Opal').first_or_create!( | |
:name => 'Opal', | |
:url => 'http://opal.elysium.emeraldreverie.org:8443' | |
) | |
proxy = SmartProxy.where(:name=>'Opal').first | |
Setting[:root_pass]='$1$oiI.6Tin$tnQzVQOfXir.eGD7Eeiwm1' # hash of '12345678' | |
Setting[:unattended_url]='http://192.168.130.1:3000' # provisioning libvirtd network | |
Environment.where(:name=>'pxe').first_or_create!(:name => 'pxe') | |
Environment.where(:name=>'image').first_or_create!(:name => 'image') | |
Domain.where(:name=>'primary.opal.local').first_or_create!( | |
:name => 'primary.opal.local', | |
:fullname => 'Primary', | |
) | |
d = Domain.where(:name=>'primary.opal.local').first | |
d.dns = proxy ; d.save! | |
Subnet.where(:name=>'Primary').first_or_create!( | |
:name => 'Primary', | |
:dhcp => proxy, | |
:dns => proxy, | |
:tftp => proxy, | |
:network => '192.168.130.0', | |
:mask => '255.255.255.0', | |
:gateway => '192.168.130.1', | |
:dns_primary => '192.168.130.1', | |
:dns_secondary => '8.8.8.8', | |
:boot_mode => 'DHCP', | |
:ipam => 'DHCP', | |
) | |
s = Subnet.where(:name=>'Primary').first | |
s.domains = [d] ; s.save! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Wheezy config | |
os = Operatingsystem.where(:description=>'Debian 7.5').first_or_create!( | |
:description => 'Debian 7.5', | |
:name => 'Debian', | |
:major => '7', | |
:minor => '5', | |
:release_name => 'wheezy', | |
:family => 'Debian') | |
os.update_attribute(:architectures,[Architecture.find_by_name('x86_64')]) | |
os.update_attribute(:media,[Medium.find_by_name('Debian mirror')]) | |
os.update_attribute(:ptables,[Ptable.find_by_name('Preseed default')]) | |
# OS defaults | |
["Preseed default", | |
"Preseed default PXELinux", | |
"Preseed default finish", | |
"Preseed default iPXE", | |
"Preseed default user data"].each do |name| | |
ct = ProvisioningTemplate.find_by_name(name) | |
ct.update_attribute(:operatingsystems, [os]) | |
# TODO make idempotent | |
osdt = OsDefaultTemplate.new | |
osdt.operatingsystem = os | |
osdt.provisioning_template = ct | |
osdt.template_kind = ct.template_kind | |
osdt.save | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Wheezy config | |
os = Operatingsystem.where(:description=>'Ubuntu 12.04').first_or_create!( | |
:description => 'Ubuntu 12.04', | |
:name => 'Ubuntu', | |
:major => '12', | |
:minor => '04', | |
:release_name => 'precise', | |
:family => 'Debian') | |
os.update_attribute(:architectures,[Architecture.find_by_name('x86_64')]) | |
os.update_attribute(:media,[Medium.find_by_name('Ubuntu mirror')]) | |
os.update_attribute(:ptables,[Ptable.find_by_name('Preseed default')]) | |
# OS defaults | |
["Preseed default", | |
"Preseed default PXELinux", | |
"Preseed default finish", | |
"Preseed default iPXE", | |
"Preseed default user data"].each do |name| | |
ct = ProvisioningTemplate.find_by_name(name) | |
ct.update_attribute(:operatingsystems, [os]) | |
# TODO make idempotent | |
osdt = OsDefaultTemplate.new | |
osdt.operatingsystem = os | |
osdt.provisioning_template = ct | |
osdt.template_kind = ct.template_kind | |
osdt.save | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Debian specific | |
operatingsystems = Operatingsystem.where(:type => 'Debian') | |
# Imaging finish script for libvirt | |
text = <<EOTEXT | |
<%# use sudo everywhere because I have no idea what user this will run as -%> | |
echo "Starting Foreman Imaging Script" | |
<%# ssh -%> | |
sudo mkdir /root/.ssh -p | |
sudo echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+1sjrMV3VKV1zE5caeqE6rwU528I8bfNxbkYuWKyiR0n9jg2fWidCGdoWC6+KzMJqGqR/wO1m5VXj6lIKYyGbYm+f3SyI6B9NJ0h4P25fLcSGRCGwCvv3vkqehcDvir1bKwGU0BewrUwI5ljm4+nfAdhDO8hnrFKg8paRrbwRL7GeR/ZMCRMEFLsQT96z0NPUk5yDYWE3xCTcVKENP89OKc1Sk0J6Xk5FFDBrEExD/0cSe2WhblvVC7sL7k3YwLKbq36UxGTer1nCzY2v9AsUpI0hmqN4fwh1XDTPR6ONASRw1fazybrbFRnh/hmsm4X8EUAzbOClwXYBMixYwKmx id_greg' >> /root/.ssh/authorized_keys | |
<%# we only change hostnames on image based provisioning -%> | |
<% if @host.capabilities.include?(:image) -%> | |
sudo sh -c 'echo "<%= @host.shortname %>" > /etc/hostname' | |
sudo hostname <%= @host.shortname %> | |
cat > /tmp/hosts << EOF | |
<%# simple snippet to generate /etc/hosts when provisioning image based systesm -%> | |
127.0.0.1 <%= @host %> <%= @host.shortname %> localhost localhost.localdomain | |
192.168.122.1 opal.elysium.emeraldreverie.org | |
::1 ip6-localhost ip6-loopback | |
fe00::0 ip6-localnet | |
ff00::0 ip6-mcastprefix | |
ff02::1 ip6-allnodes | |
ff02::2 ip6-allrouters | |
EOF | |
sudo mv /tmp/hosts /etc/hosts | |
<% end -%> | |
# ACNG config | |
sudo sh -c 'echo "Acquire::http::Proxy \\\"http://<%= @host.subnet.gateway %>:3142\\\";" > /etc/apt/apt.conf.d/95proxy' | |
<% unless (@host.params['disable-puppet'] && @host.params['disable-puppet'] == 'true') -%> | |
wget http://apt.puppetlabs.com/puppetlabs-release-<%= @host.operatingsystem.release_name %>.deb -q -O /tmp/pl-release.deb | |
sudo dpkg -i /tmp/pl-release.deb | |
sudo apt-get update | |
sudo apt-get install -y puppet | |
cat > /tmp/puppet.conf << EOF | |
<%= snippets "puppet.conf" -%> | |
EOF | |
sudo mv /tmp/puppet.conf /etc/puppet/puppet.conf | |
sudo /bin/sed -i 's/^START=no/START=yes/' /etc/default/puppet | |
sudo /bin/touch /etc/puppet/namespaceauth.conf | |
sudo /usr/bin/puppet agent --config /etc/puppet/puppet.conf --onetime --tags no_such_tag --server <%= @host.puppetmaster %> --no-daemonize | |
sudo /etc/init.d/puppet start | |
<% end -%> | |
<% unless (@host.params['disable-foreman'] && @host.params['disable-foreman'] == 'true') -%> | |
<% repo = @host.params['foreman-repo'] || 'nightly' -%> | |
echo "deb http://deb.theforeman.org/ <%= @host.operatingsystem.release_name %> <%= repo %>" > /etc/apt/sources.list.d/foreman.list | |
echo "deb http://deb.theforeman.org/ plugins <%= repo %>" >> /etc/apt/sources.list.d/foreman.list | |
wget -q http://deb.theforeman.org/foreman.asc -O- | apt-key add - | |
apt-get update | |
<% end -%> | |
echo "Finished Foreman OpenStack Script" | |
exit 0 | |
EOTEXT | |
ct = ProvisioningTemplate.where(:name=>'Preseed image finish').first_or_create!( | |
:name => 'Preseed image finish', | |
:template => text, | |
:operatingsystems => operatingsystems, | |
:template_kind => TemplateKind.find_by_name('finish'), | |
) | |
tc=TemplateCombination.new | |
tc.provisioning_template_id = ct.id | |
tc.environment_id = Environment.find_by_name('image').id | |
tc.save | |
## Libvirt | |
cr=ComputeResource.where(:name=>'Opal').first_or_create | |
cr.name = "Opal" | |
cr.description = "Local laptop libvirt" | |
cr.url = "qemu:///system" | |
cr.provider = 'Libvirt' | |
cr.attrs = { :display => "SPICE", :setpw => 0 } | |
cr.save | |
i=Image.where(:name=>'Wheezy Image').first_or_create | |
i.name = 'Wheezy Image' | |
i.operatingsystem = Operatingsystem.find_by_title('Debian 7.5') | |
i.compute_resource = ComputeResource.find_by_name('Opal') | |
i.architecture = Architecture.find_by_name('x86_64') | |
i.uuid = '/home/images/debian-wheezy-7.0.0-3-amd64.qcow2' | |
i.username = 'debian' | |
i.password = 'debian' | |
i.save | |
ComputeAttribute.create( | |
:compute_profile_id => ComputeProfile.find('1-Small').id, | |
:compute_resource_id => ComputeResource.find_by_name('Opal').id, | |
:vm_attrs => { | |
"cpus" => "1", | |
"memory" => "1073741824", | |
"nics_attributes" => { | |
"0" => { | |
"type" => "network", | |
"_delete" => "", | |
"network" => "primary", | |
"bridge" => "wlp3s0", | |
"model" => "virtio" | |
} | |
}, | |
"volumes_attributes" => { | |
"0" => { | |
"pool_name" => "ImageHome", | |
"capacity" => "5G", | |
"allocation" => "0G", | |
"format_type" => "qcow2", | |
"_delete" => "" | |
} | |
} | |
}, | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file is a local addition which allows a dev to | |
# blow away his DB and set it back up with his own | |
# proxies/subnet/domains/etc. | |
proxy = SmartProxy.find_by_name('Sapphire') | |
# Conveniance | |
hg=Hostgroup.where(:name=>'PXE').first_or_create | |
hg.name = 'PXE' | |
hg.environment = Environment.find_by_name('pxe') | |
hg.puppet_proxy = proxy | |
hg.puppet_ca_proxy = proxy | |
hg.operatingsystem = Operatingsystem.first | |
hg.architecture = Architecture.find_by_name('x86_64') | |
hg.medium = Medium.find_by_name('Debian mirror') | |
hg.ptable = Ptable.find_by_name('Preseed default') | |
hg.subnet = Subnet.find_by_name('Primary') | |
hg.domain = Domain.find_by_fullname('Primary') | |
hg.save | |
Hostgroup.where(:name=>'Image').first_or_create | |
hg.name = 'Image' | |
hg.environment = Environment.find_by_name('image') | |
hg.puppet_proxy = proxy | |
hg.puppet_ca_proxy = proxy | |
hg.operatingsystem = Operatingsystem.first | |
hg.architecture = Architecture.find_by_name('x86_64') | |
hg.medium = Medium.find_by_name('Debian mirror') | |
hg.ptable = Ptable.find_by_name('Preseed default') | |
hg.subnet = Subnet.find_by_name('Primary') | |
hg.domain = Domain.find_by_fullname('Primary') | |
hg.save | |
## Openstack | |
#c=ComputeResource.find_or_create_by_name!( | |
# :name => 'OS1_Private', | |
# :description => 'Red Hat OS1 Private Openstack Cloud', | |
# :url => 'http://control.os1.phx2.redhat.com:5000/v2.0/tokens', | |
# :provider => 'Openstack', | |
# :user => 'gsutclif', | |
# :password => '7c8141af', | |
# :attrs => { :tenant => 'Systems Management' } | |
#) | |
#c.send(:setup_key_pair) #Why does this not fire on after_create like it should?! | |
#ComputeAttribute.create( | |
# :compute_profile_id => ComputeProfile.find('1-Small').id, | |
# :compute_resource_id => ComputeResource.find_by_name('Sapphire').id, | |
# :vm_attrs => { "cpus" => "1", "memory" => "1073741824", "nics_attributes" => {"new_nics" => {"type" => "bridge", "_delete" => "", "bridge" => "wlp3s0", "model" => "virtio"}, "0" => {"type" => "network", "_delete" => "", "network" => "provisioning", "bridge" => "wlp3s0", "model" => "virtio"}}, "volumes_attributes" => {"new_volumes" => {"pool_name" => "default", "capacity" => "10G", "allocation" => "0G", "format_type" => "raw", "_delete" => ""}, "0" => {"pool_name" => "ImageHome", "capacity" => "5G", "allocation" => "0G", "format_type" => "qcow2", "_delete" => ""}}}, | |
#) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment