--- - name: Something hosts: temp become: true gather_facts: false vars: file_name: /boot/ansible.ini file_contents: | Hello world - reboot trigger tasks: - name: Set file contents ansible.builtin.copy: dest: /boot/ansible.ini owner: root group: root mode: "0600" content: "{{ file_contents }}" register: r_touch_file - name: Debug r_touch_file ansible.builtin.debug: var: r_touch_file - name: Reboot host if file changes # noqa: no-handler ansible.builtin.import_role: name: verified_reboot when: - r_touch_file['changed'] | bool