Skip to content

Instantly share code, notes, and snippets.

@TJM
Last active August 5, 2016 05:46
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 TJM/e3de0cfed2cfd4733c16 to your computer and use it in GitHub Desktop.
Save TJM/e3de0cfed2cfd4733c16 to your computer and use it in GitHub Desktop.
LarkIT-Foreman-Finish-Scripts
<%#
kind: snippet
name: fix_hosts
%>
echo "<%= @host %>" > /etc/hostname
hostname <%= @host %>
# CentOS 7 (Fedora 19+?) uses hostnamectl
[ -x /usr/bin/hostnamectl ] && /usr/bin/hostnamectl set-hostname <%= @host %>
# Cloud Init Data needs to be told to leave the hostname alone.
[ -f /etc/cloud/cloud.cfg ] && echo 'preserve_hostname: true' >> /etc/cloud/cloud.cfg
cat > /etc/hosts << EOF
<%# simple snippet to generate /etc/hosts when provisioning image based systems -%>
127.0.0.1 <%= @host %> <%= @host.shortname %> localhost localhost.localdomain
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
<%#
kind: finish
name: LarkIT-CentOS-Finish
oses:
- CentOS 4
- CentOS 5
- CentOS 6
- CentOS 7
- Fedora 16
- Fedora 17
- Fedora 18
- Fedora 19
- Fedora 20
%>
<%
rhel_compatible = @host.operatingsystem.family == 'Redhat' && @host.operatingsystem.name != 'Fedora'
os_major = @host.operatingsystem.major.to_i
pm_set = @host.puppetmaster.empty? ? false : true
puppet_enabled = pm_set || @host.params['force-puppet']
%>
# Ensure SELINUX is ENFORCING (needed on DigitalOcean droplets) - reboot at the end
[ -f /etc/selinux/config ] && sed -i -e 's/SELINUX=disabled/SELINUX=enforcing/' /etc/selinux/config
<% if @host.provision_method == 'image' && ! root_pass.empty? -%>
# Install the root password
echo 'root:<%= root_pass -%>' | /usr/sbin/chpasswd -e
<% end -%>
<%= snippet "fix_hosts" -%>
<% if rhel_compatible -%>
<%= snippet "epel" -%>
<% end -%>
<% if puppet_enabled -%>
<% if @host.params['enable-puppetlabs-repo'] && @host.params['enable-puppetlabs-repo'] == 'true' -%>
<% if @host.operatingsystem.name == 'Fedora' -%>
rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-fedora-<%= os_major -%>.noarch.rpm
<% else -%>
rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-<%= os_major -%>.noarch.rpm
<% end -%>
<% end -%>
yum -t -y -e 0 install puppet
<% end -%>
#update local time
echo "updating system time"
/usr/sbin/ntpdate -sub <%= @host.params['ntp-server'] || '0.fedora.pool.ntp.org' %>
/usr/sbin/hwclock --systohc
<% if @host.info["parameters"]["realm"] && @host.otp && @host.realm && @host.realm.realm_type == "FreeIPA" -%>
<%= snippet "freeipa_register" %>
<% end -%>
# update all the base packages from the updates repository
yum -t -y -e 0 update
<% if puppet_enabled %>
echo "Configuring puppet"
cat > /etc/puppet/puppet.conf << EOF
<%= snippet 'puppet.conf' %>
EOF
# Setup puppet to run on system reboot
/sbin/chkconfig --level 345 puppet on
/usr/bin/puppet agent --config /etc/puppet/puppet.conf -o --tags no_such_tag <%= @host.puppetmaster.blank? ? '' : "--server #{@host.puppetmaster}" %> --no-daemonize
<% end -%>
# Borrowed from Preseed finish
/usr/bin/wget --no-proxy --quiet --output-document=/dev/null --no-check-certificate <%= foreman_url('built') %>
# LARK IT Customization - Reboot after likely installing updates above
# -- also this helps because normally after a kickstart the system reboots,
# but while post-provisioning a cloud server, there is no such reboot.
/sbin/shutdown -r +1 Rebooting to apply updates &
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment