diff --git a/roles/kubernetes/preinstall/tasks/etchosts.yml b/roles/kubernetes/preinstall/tasks/etchosts.yml
index dd8562b8cd610189d37bacff33439af090a5847d..6f21ffa8f100d5f28fa81b5302ab80b7a57cdaca 100644
--- a/roles/kubernetes/preinstall/tasks/etchosts.yml
+++ b/roles/kubernetes/preinstall/tasks/etchosts.yml
@@ -1,14 +1,15 @@
 ---
 - name: Hosts | populate inventory into hosts file
-  lineinfile:
+  blockinfile:
     dest: /etc/hosts
-    regexp: "^{{ hostvars[item]['access_ip'] | default(hostvars[item]['ip'] | default(hostvars[item].ansible_default_ipv4.address)) }} {{ item }}$"
-    line: "{{ hostvars[item]['access_ip'] | default(hostvars[item]['ip'] | default(hostvars[item].ansible_default_ipv4.address)) }} {{ item }}"
+    block: |-
+      {% for item in groups['all'] -%}
+      {{ hostvars[item]['access_ip'] | default(hostvars[item]['ip'] | default(hostvars[item].ansible_default_ipv4.address)) }} {{ item }}
+      {% endfor %}
     state: present
     create: yes
     backup: yes
-  when: hostvars[item].ansible_default_ipv4.address is defined
-  with_items: "{{ groups['all'] }}"
+    marker: "# Ansible inventory hosts {mark}"
 
 - name: Hosts | populate kubernetes loadbalancer address into hosts file
   lineinfile: