diff --git a/tasks/main.yml b/tasks/main.yml
index cccda87e16d9656084a7c109674a3c7609e87e11..4b29d708fd263a11730c548eea685cc64aa066d6 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -20,6 +20,9 @@
         regexp: '^127.0.1.1'
         line: '127.0.1.1 {{ hostname }}'
         state: present
+    - name: Set 'ansible_hostname' fact to the new hostname
+      set_fact:
+        ansible_hostname: '{{ hostname }}'
   when: hostname is defined and hostname != None and hostname != ''
 
 # Install common packages and utils