---

- name: set hostname
  hostname: name={{ inventory_hostname }}{{ domain_to_set }}

---

- name: set hostname
  hostname: name={{ inventory_hostname }}{{ domain_to_set }}
  register: result

- name: update ansible_fqdn and ansible_hostname
  set_fact:
    ansible_fqdn: "{{ inventory_hostname }}{{ domain_to_set }}"
    ansible_hostname: "{{ inventory_hostname }}"
  when: result.changed

Update facts when hostname is changed in set_hostname role.
Update facts when hostname is changed in set_hostname role.
