--- - name: Set hostname ansible.builtin.hostname: name: "{{ hostname }}" - name: Ensure /etc/hosts has proper hostname entry ansible.builtin.lineinfile: path: /etc/hosts regexp: "^127\\.0\\.1\\.1" line: "127.0.1.1 {{ hostname }}" create: yes backup: yes - name: Reboot system ansible.builtin.reboot: msg: "Rebooting after hostname change" connect_timeout: 5 reboot_timeout: 300 pre_reboot_delay: 0 post_reboot_delay: 10