<?xml version="1.0" encoding="UTF-8"?>
<%#
kind: provision
name: AutoYaST SLES default
oses:
- SLES 11
- SLES 12
%>
<%
  os_major = @host.operatingsystem.major.to_i
  os_minor = @host.operatingsystem.minor.to_i
  # safemode renderer does not support unary negation
  pm_set = @host.puppetmaster.empty? ? false : true
  puppet_enabled = pm_set || @host.params['force-puppet'] && @host.params['force-puppet'] == 'true'
  salt_enabled = @host.params['salt_master'] ? true : false
  sles_minor_string = (os_minor == 0) ? '' : "_SP#{os_minor}"
  spacewalk_enabled = @host.params['spacewalk_host'] ? true : false
%>
<!DOCTYPE profile>
<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns">
  <general>
    <mode>
      <confirm config:type="boolean">false</confirm>
      <final_reboot config:type="boolean">true</final_reboot>
    </mode>
  </general>
  <networking>
    <dns>
      <hostname><%= @host.name %></hostname>
      <resolv_conf_policy>auto</resolv_conf_policy>
<% if @host.domain -%>
      <searchlist config:type="list">
        <search><%= @host.domain %></search>
      </searchlist>
<% end -%>
    </dns>
    <interfaces config:type="list">
      <interface>
        <bootproto>dhcp</bootproto>
        <device>eth0</device>
        <startmode>auto</startmode>
        <usercontrol>no</usercontrol>
      </interface>
    </interfaces>
  </networking>
  <ntp-client>
    <configure_dhcp config:type="boolean">false</configure_dhcp>
    <peers config:type="list">
      <peer>
        <address><%= @host.params['ntp-server'] || '0.opensuse.pool.ntp.org' %></address>
        <initial_sync config:type="boolean">true</initial_sync>
        <options></options>
        <type>server</type>
      </peer>
    </peers>
    <start_at_boot config:type="boolean">true</start_at_boot>
    <start_in_chroot config:type="boolean">true</start_in_chroot>
  </ntp-client>
  <%= @host.diskLayout %>
  <runlevel>
    <default>3</default>
    <services config:type="list">
      <service>
        <service_name>sshd</service_name>
        <service_status>enable</service_status>
      </service>
    </services>
  </runlevel>
  <software>
    <patterns config:type="list">
      <pattern>Minimal</pattern>
    </patterns>
    <packages config:type="list">
      <package>less</package>
      <package>lsb-release</package>
      <package>openssh</package>
      <package>vim</package>
<% if puppet_enabled -%>
      <package>rubygem-puppet</package>
<% end -%>
<% if salt_enabled -%>
      <package>salt-minion</package>
<% end -%>
<% if spacewalk_enabled -%>
      <package>rhn-setup</package>
<% end -%>
    </packages>
  </software>
  <users config:type="list">
    <user>
      <username>root</username>
      <encrypted config:type="boolean">true</encrypted>
      <fullname>root</fullname>
      <gid>0</gid>
      <home>/root</home>
      <shell>/bin/bash</shell>
      <uid>0</uid>
      <user_password><%= root_pass %></user_password>
    </user>
  </users>
  <scripts>
    <chroot-scripts config:type="list">
      <script>
        <filename>cp-resolv.sh</filename>
        <chrooted config:type="boolean">false</chrooted>
        <interpreter>shell</interpreter>
        <notification>Copying resolv.conf into chroot ...</notification>
        <source><![CDATA[
cp /etc/resolv.conf /mnt/etc
]]>
        </source>
      </script>
      <script>
        <filename>foreman.sh</filename>
        <chrooted config:type="boolean">true</chrooted>
        <interpreter>shell</interpreter>
        <notification>Setting up Puppet / Foreman ...</notification>
        <source><![CDATA[
/bin/hostname <%= @host.name %>
<% if puppet_enabled -%>
cat > /etc/puppet/puppet.conf << EOF
<%= snippet 'puppet.conf' -%>
EOF
if [ -f "/etc/sysconfig/puppet" ]
then
/usr/bin/sed -ie s/^PUPPET_SERVER=.*/PUPPET_SERVER=<%= @host.puppetmaster.blank? ? '' : @host.puppetmaster %>/ /etc/sysconfig/puppet
fi
/usr/bin/puppet agent --config /etc/puppet/puppet.conf -o --tags no_such_tag <%= @host.puppetmaster.blank? ? '' : "--server #{@host.puppetmaster}" %> --no-daemonize
/sbin/chkconfig puppet on -f
<% end -%>

<% if salt_enabled %>
cat > /etc/salt/minion << EOF
<%= snippet 'saltstack_minion' %>
EOF
# Setup salt-minion to run on system reboot
chkconfig salt-minion on
# Running salt-call to trigger key signing
salt-call --no-color --grains >/dev/null
<% end -%>
<% if spacewalk_enabled -%>
<%= snippet 'redhat_register' %>
<% end -%>

/usr/bin/curl -o /dev/null -k '<%= foreman_url %>'

rm /etc/resolv.conf
]]>
        </source>
      </script>
    </chroot-scripts>
  </scripts>
  <keyboard>
    <keymap>english-us</keymap>
  </keyboard>
  <timezone>
    <hwclock>UTC</hwclock>
    <timezone><%= @host.params['time-zone'] || 'Etc/UTC' %></timezone>
  </timezone>
  <add-on>
    <add_on_products config:type="list">
<% if puppet_enabled -%>
      <listentry>
        <media_url><![CDATA[http://download.opensuse.org/repositories/systemsmanagement:/puppet/SLE_<%= os_major %><%= sles_minor_string %>/]]></media_url>
        <name>systemsmanagement_puppet</name>
        <product>systemsmanagement_puppet</product>
        <product_dir>/</product_dir>
        <signature-handling>
          <accept_non_trusted_gpg_key>
            <all config:type="boolean">false</all>
            <keys config:type="list">
              <keyid>2ABFA143A0E46E11</keyid>
            </keys>
          </accept_non_trusted_gpg_key>
          <import_gpg_key>
            <all config:type="boolean">false</all>
            <keys config:type="list">
              <keyid>2ABFA143A0E46E11</keyid>
            </keys>
          </import_gpg_key>
        </signature-handling>
      </listentry>
<% if os_major < 12 -%>
      <listentry>
        <media_url><![CDATA[http://download.opensuse.org/repositories/devel:languages:ruby:backports/SLE_<%= os_major %><%= sles_minor_string %>/]]></media_url>
        <name>devel_languages_ruby_backports</name>
        <product>devel_languages_ruby_backports</product>
        <product_dir>/</product_dir>
        <signature-handling>
          <accept_non_trusted_gpg_key>
            <all config:type="boolean">false</all>
            <keys config:type="list">
              <keyid>9AF0C9A20E9AF123</keyid>
            </keys>
          </accept_non_trusted_gpg_key>
          <import_gpg_key>
            <all config:type="boolean">false</all>
            <keys config:type="list">
              <keyid>9AF0C9A20E9AF123</keyid>
            </keys>
          </import_gpg_key>
        </signature-handling>
      </listentry>
      <listentry>
<!-- you have to update the next line with the actual URL of your SDK -->
        <media_url>http://<your_server_here>/iso/suse/SDK/<%= os_major %>.<%= os_minor %>/<%= @host.architecture %>/</media_url>
        <product>SuSE-Linux-SDK</product>
        <product_dir>/</product_dir>
        <name>SuSE-Linux-SDK</name>
      </listentry>
<% end -%>
<% end -%>
<% if salt_enabled -%>
      <listentry>
        <media_url><![CDATA[http://download.opensuse.org/repositories/devel:languages:python/SLE_<%= os_major %><%= sles_minor_string %>/]]></media_url>
        <name>devel_languages_python</name>
        <product>devel_languages_python</product>
        <product_dir>/</product_dir>
        <signature-handling>
          <accept_non_trusted_gpg_key>
            <all config:type="boolean">false</all>
            <keys config:type="list">
              <keyid>27163A4EEDF0D733</keyid>
            </keys>
          </accept_non_trusted_gpg_key>
          <import_gpg_key>
            <all config:type="boolean">false</all>
            <keys config:type="list">
              <keyid>27163A4EEDF0D733</keyid>
            </keys>
          </import_gpg_key>
        </signature-handling>
      </listentry>
<% end -%>
<% if spacewalk_enabled -%>
      <listentry>
        <media_url><![CDATA[http://download.opensuse.org/repositories/systemsmanagement:/spacewalk/SLE_<%= os_major %><%= sles_minor_string %>/]]></media_url>
        <name>systemsmanagement_spacewalk</name>
        <product>systemsmanagement_spacewalk</product>
        <product_dir>/</product_dir>
        <signature-handling>
          <accept_non_trusted_gpg_key>
            <all config:type="boolean">false</all>
            <keys config:type="list">
              <keyid>2ABFA143A0E46E11</keyid>
            </keys>
          </accept_non_trusted_gpg_key>
          <import_gpg_key>
            <all config:type="boolean">false</all>
            <keys config:type="list">
              <keyid>2ABFA143A0E46E11</keyid>
            </keys>
          </import_gpg_key>
        </signature-handling>
      </listentry>
<% end -%>
    </add_on_products>
  </add-on>
</profile>
