<?xml version="1.0" encoding="UTF-8"?>
<%#
kind: provision
name: Community AutoYaST SLES
oses:
- SLES 11
%>
<%
  # safemode renderer does not support unary negation
  pm_set = @host.puppetmaster.empty? ? false : true
  puppet_enabled = pm_set || @host.params['force-puppet']
%>
<!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>
  </runlevel>
  <software>
    <base>default</base>
    <packages config:type="list">
<% if puppet_enabled %>
      <package>puppet</package>
      <package>rubygem-ruby-augeas</package>
<% end -%>
      <package>wget</package>
    </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>
    <post-scripts config:type="list">
      <script>
        <filename>post.sh</filename>
        <interpreter>shell</interpreter>
        <network_needed config:type="boolean">true</network_needed>
        <notification>Setting up Puppet / Foreman ...</notification>
        <debug config:type="boolean">true</debug>
        <source><![CDATA[
<% 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 -%>

/usr/bin/wget -q -O /dev/null --no-check-certificate <%= foreman_url %>
]]>
        </source>
      </script>
    </post-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">
      <listentry>
<!-- you have to update the next line with the actual URL of your SDK -->
        <media_url>http://<your_server_here>/iso/suse/SDK/<%= @host.operatingsystem.major %>.<%= @host.operatingsystem.minor %>/<%= @host.architecture %>/</media_url>
        <product>SuSE-Linux-SDK</product>
        <product_dir>/</product_dir>
        <name>SuSE-Linux-SDK</name>
      </listentry>
<% if puppet_enabled %>
      <listentry>
        <media_url><![CDATA[http://download.opensuse.org/repositories/systemsmanagement:/puppet/SLE_<%= @host.operatingsystem.major %>_SP<%= @host.operatingsystem.minor %>/]]></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>
<% end -%>
    </add_on_products>
  </add-on>
</profile>
