@@ -136,23 +136,30 @@ def initialize_options(arguments: list[str] | None = None) -> BaseFileLock | Non
136136 options .warn_list = [normalize_tag (tag ) for tag in options .warn_list ]
137137
138138 options .configured = True
139- options .cache_dir = get_cache_dir (pathlib .Path (options .project_dir ))
139+ if not (
140+ options .version
141+ or options .list_profiles
142+ or options .list_rules
143+ or options .list_tags
144+ ):
145+ options .cache_dir = get_cache_dir (pathlib .Path (options .project_dir ))
140146
141147 # add a lock file so we do not have two instances running inside at the same time
142148 if options .cache_dir :
143149 options .cache_dir .mkdir (parents = True , exist_ok = True )
144150
145- if not options .offline : # pragma: no cover
146- cache_dir_lock = FileLock (
147- f"{ options .cache_dir } /.lock" ,
148- )
149- try :
150- cache_dir_lock .acquire (timeout = 180 )
151- except Timeout : # pragma: no cover
152- _logger .error ( # noqa: TRY400
153- "Timeout waiting for another instance of ansible-lint to release the lock." ,
151+ # lock file can only be used if cache_dir is set and writable
152+ if not options .offline : # pragma: no cover
153+ cache_dir_lock = FileLock (
154+ f"{ options .cache_dir } /.lock" ,
154155 )
155- sys .exit (RC .LOCK_TIMEOUT )
156+ try :
157+ cache_dir_lock .acquire (timeout = 180 )
158+ except Timeout : # pragma: no cover
159+ _logger .error ( # noqa: TRY400
160+ "Timeout waiting for another instance of ansible-lint to release the lock." ,
161+ )
162+ sys .exit (RC .LOCK_TIMEOUT )
156163
157164 # Avoid extra output noise from Ansible about using devel versions
158165 if "ANSIBLE_DEVEL_WARNING" not in os .environ : # pragma: no branch
0 commit comments