@@ -293,15 +293,23 @@ def matchtask(
293293 # If the task registers a variable
294294 registered_var = task .get ("register" , None )
295295 if registered_var :
296- match_error = self . get_var_naming_matcherror (
297- registered_var ,
298- prefix = role_prefix ,
299- file = file or Lintable ( "" ),
296+ registered_vars = (
297+ registered_var . keys ()
298+ if isinstance ( registered_var , dict )
299+ else ( registered_var ,)
300300 )
301- if match_error :
302- match_error .message += f" (register: { registered_var } )"
303- match_error .lineno = task .line
304- results .append (match_error )
301+ for key in registered_vars :
302+ if isinstance (key , str ) and key .startswith ("__" ):
303+ continue
304+ match_error = self .get_var_naming_matcherror (
305+ key ,
306+ prefix = role_prefix ,
307+ file = file or Lintable ("" ),
308+ )
309+ if match_error :
310+ match_error .message += f" (register: { key } )"
311+ match_error .lineno = task .line
312+ results .append (match_error )
305313
306314 return results
307315
@@ -491,6 +499,19 @@ def test_var_naming_with_set_fact_and_cacheable() -> None:
491499 assert result .returncode == RC .SUCCESS
492500 assert "var-naming" not in result .stdout
493501
502+ def test_var_naming_with_register_projection (
503+ config_options : Options ,
504+ app : App ,
505+ ) -> None :
506+ """Test register projection variable names."""
507+ rules = RulesCollection (app = app , options = config_options )
508+ rules .register (VariableNamingRule ())
509+ results = Runner (
510+ Lintable ("test/schemas/test/playbooks/register_projection.yml" ),
511+ rules = rules ,
512+ ).run ()
513+ assert not results
514+
494515 def test_var_naming_with_include_role_import_role () -> None :
495516 """Test with include role and import role."""
496517 role_path = "examples/.test_collection/roles/my_role/tasks/main.yml"
0 commit comments