




# Select package manager for the OS (sets the $PKG_MANAGER* variables)
if [ -z "$PKG_MANAGER" ]; then
  if [ -f /etc/os-release ] ; then
    . /etc/os-release
  fi
  
  if [ "${NAME%.*}" = 'FreeBSD' ]; then
    PKG_MANAGER='pkg'
    PKG_MANAGER_INSTALL="${PKG_MANAGER} install -y"
    PKG_MANAGER_REMOVE="${PKG_MANAGER} delete -y"
    PKG_MANAGER_UPGRADE="${PKG_MANAGER} install -y"
  elif [ -f /etc/fedora-release -o -f /etc/redhat-release -o -f /etc/amazon-linux-release -o -f /etc/system-release ]; then
    PKG_MANAGER='dnf'
    if [ -f /etc/redhat-release -a "${VERSION_ID%.*}" -le 7 ]; then
      PKG_MANAGER='yum'
    elif [ -f /etc/system-release ]; then
      PKG_MANAGER='yum'
    fi
    PKG_MANAGER_INSTALL="${PKG_MANAGER} install -y"
    PKG_MANAGER_REMOVE="${PKG_MANAGER} remove -y"
    PKG_MANAGER_UPGRADE="${PKG_MANAGER} upgrade -y"
  elif [ -f /etc/debian_version ]; then
    PKG_MANAGER='apt-get'
    PKG_MANAGER_INSTALL="${PKG_MANAGER} -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install -y"
    PKG_MANAGER_REMOVE="${PKG_MANAGER} remove -y"
    PKG_MANAGER_UPGRADE="${PKG_MANAGER} -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' -o APT::Get::Upgrade-Allow-New='true' upgrade -y"
  elif [ -f /etc/arch-release ]; then
    PKG_MANAGER='pacman'
    PKG_MANAGER_INSTALL="${PKG_MANAGER} --noconfirm -S"
    PKG_MANAGER_REMOVE="${PKG_MANAGER} --noconfirm -R"
    PKG_MANAGER_UPGRADE="${PKG_MANAGER} --noconfirm -S"
  elif [ x$ID = xopensuse-tumbleweed -o x$ID = xsles ]; then
    PKG_MANAGER='zypper'
    PKG_MANAGER_INSTALL="${PKG_MANAGER} --non-interactive install --auto-agree-with-licenses"
    PKG_MANAGER_REMOVE="${PKG_MANAGER} --non-interactive remove"
    PKG_MANAGER_UPGRADE="${PKG_MANAGER} --non-interactive update"
  fi
fi



echo "blacklist amodule" >> /etc/modprobe.d/blacklist.conf



apt-get update
apt-get install -y puppet

cat > /etc/puppet/puppet.conf << EOF
[main]
vardir = /var/lib/puppet
logdir = /var/log/puppet
rundir = /var/run/puppet
ssldir = \$vardir/ssl

[agent]
pluginsync      = true
report          = true
certname        = snapshot-ipv4-dhcp-deb10

EOF


if [ -f "/etc/default/puppet" ]
then
/bin/sed -i 's/^START=no/START=yes/' /etc/default/puppet
fi
/usr/bin/puppet agent --enable

# export a custom fact called 'is_installer' to allow detection of the installer environment in Puppet modules
export FACTER_is_installer=true
# passing a non-existent tag like "no_such_tag" to the puppet agent only initializes the node
# You can select specific tag(s) with the "run-puppet-in-installer-tags" parameter
# or set a full puppet run by setting "run-puppet-in-installer" = true
echo "Performing initial puppet run for --tags no_such_tag"
/usr/bin/puppet agent --config /etc/puppet/puppet.conf --onetime --tags no_such_tag  --no-daemonize
systemctl enable puppet



real=`ip -o link | awk '/00-f0-54-1a-7e-e0/ {print $2;}' | sed s/://`
cat << EOF > /etc/network/interfaces
#loopback
auto lo
iface lo inet loopback

#eth0
auto $real
allow-hotplug $real
iface $real inet dhcp
EOF

cat << EOF-2929810d > /etc/systemd/system/ansible-callback.service
[Unit]
Description=Provisioning callback to Ansible Tower
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/curl -k -s --data "host_config_key=" https://host.example.com/api/controller/v2/job_templates/20/callback/
ExecStartPost=/usr/bin/systemctl disable ansible-callback

[Install]
WantedBy=multi-user.target
EOF-2929810d
# Runs during first boot, removes itself
systemctl enable ansible-callback
if [ -x /usr/bin/curl ]; then
  /usr/bin/curl -o /dev/null -H 'Content-Type: text/plain' --noproxy \* --silent 'http://foreman.example.com/unattended/built'
elif [ -x /usr/bin/wget ]; then
  /usr/bin/wget -q -O /dev/null --method POST --header 'Content-Type: text/plain' --no-proxy 'http://foreman.example.com/unattended/built'
else
  wget -q -O /dev/null --header 'Content-Type: text/plain' 'http://foreman.example.com/unattended/built'
fi

if [ -x "$(command -v subscription-manager)" ] ; then
  subscription-manager facts --update
fi
PATH=/usr/bin:/usr/sbin:/bin:/sbin:$PATH shutdown -r +1
