diff --git a/tasks/lock_root.yml b/tasks/lock_root.yml
index 8bab4fd20bd4a7a7593a387e30676e03095c09cf..9579cca7461cb97ada79626b4ca7805b6eb25e13 100644
--- a/tasks/lock_root.yml
+++ b/tasks/lock_root.yml
@@ -5,7 +5,7 @@
     name: root
     expires: 1.0
   register: lock_root
-  changed_when: not 'no changes' in lock_root.stderr
+  changed_when: not (lock_root.stderr is defined and 'no changes' in lock_root.stderr)
 
 - name: Disable root SSH login
   lineinfile: