diff --git a/tasks/main.yml b/tasks/main.yml
index efe8f5d6e182556fdb342d6e3d80da8a144ecca5..2bdc6dd54db2d80785dacfddb465f97904f755c0 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -170,7 +170,7 @@
   connection: local
   become: false
   delegate_to: localhost
-  when: docker_userns_remap and dockremap_subuid_output.stdout is defined
+  when: docker_userns_remap and dockremap_subuid_output.stdout is defined and not ansible_check_mode
 
 - name: Save gid to hostvars for dockremap user
   lineinfile:
@@ -182,4 +182,4 @@
   connection: local
   become: false
   delegate_to: localhost
-  when: docker_userns_remap and dockremap_subgid_output.stdout is defined
+  when: docker_userns_remap and dockremap_subgid_output.stdout is defined and not ansible_check_mode