<%#
kind: user_data
name: Preseed default user data
oses:
- Debian 6.0
- Debian 7.
- Debian 8.
- Ubuntu 12.04
- Ubuntu 14.04
-%>
#!/bin/bash

<%# Cloud instances frequently have incorrect hosts data %>
<%= snippet 'fix_hosts' %>

<%
  # 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'
%>
<% if puppet_enabled %>
apt-get update
apt-get install -y puppet
cat > /etc/puppet/puppet.conf << EOF
<%= snippet 'puppet.conf' %>
EOF
if [ -f "/etc/default/puppet" ]
then
/bin/sed -i 's/^START=no/START=yes/' /etc/default/puppet
fi
/bin/touch /etc/puppet/namespaceauth.conf
/usr/bin/puppet agent --enable
/usr/bin/puppet agent --config /etc/puppet/puppet.conf --onetime --tags no_such_tag <%= @host.puppetmaster.blank? ? '' : "--server #{@host.puppetmaster}" %> --no-daemonize
<% end -%>

# UserData still needs wget to mark as finished
/usr/bin/wget --quiet --output-document=/dev/null --no-check-certificate <%= foreman_url('built') %>
