Add /etc/hostname and /etc/mailname setting
Add these defaults:
etchosts_hostname: "{{ inventory_hostname }}"
etchosts_mailname: "{{ inventory_hostname }}"
And use ansible.builtin.hostname to update /etc/hostname
and either lineinfile or the template module to update /etc/mailname
.