Hostname and resolv.conf are overwritten after reboot

Hi.
I have foreman 3.4.1 and i am trying to install ubuntu 20.04.6 using cloud init.
from the finish template i update the hostname and resolv.conf but after reboot i see that the changes havent been saved

<% if @host.operatingsystem.major.to_i > 16 -%>
  /usr/bin/rm -f /etc/resolv.conf
  systemctl stop systemd-resolved.service
  systemctl disable systemd-resolved.service
  rm -f /etc/resolv.conf
<% end %>

cat <<EOF > /etc/resolv.conf
search <%= @host.domain %>
nameserver 10.xx.xx.xx
EOF

and

echo "<%= @host.name %>" > /etc/hostname

has anyone faced such an issue before ?