@@ -466,8 +466,9 @@ def certificate_managed(
466466 if file_args .get ("follow_symlinks" , True ):
467467 real_name = os .path .realpath (name )
468468 else :
469- # workaround https://github.com/saltstack/salt/issues/31802
470- __salt__ ["file.remove" ](name )
469+ if not __opts__ ["test" ]:
470+ # workaround https://github.com/saltstack/salt/issues/31802
471+ __salt__ ["file.remove" ](name )
471472 replace = True
472473
473474 if __salt__ ["file.file_exists" ](real_name ):
@@ -871,8 +872,9 @@ def crl_managed(
871872 if file_args .get ("follow_symlinks" , True ):
872873 real_name = os .path .realpath (name )
873874 else :
874- # workaround https://github.com/saltstack/salt/issues/31802
875- __salt__ ["file.remove" ](name )
875+ if not __opts__ ["test" ]:
876+ # workaround https://github.com/saltstack/salt/issues/31802
877+ __salt__ ["file.remove" ](name )
876878 replace = True
877879
878880 if __salt__ ["file.file_exists" ](real_name ):
@@ -1106,8 +1108,9 @@ def csr_managed(
11061108 if file_args .get ("follow_symlinks" , True ):
11071109 real_name = os .path .realpath (name )
11081110 else :
1109- # workaround https://github.com/saltstack/salt/issues/31802
1110- __salt__ ["file.remove" ](name )
1111+ if not __opts__ ["test" ]:
1112+ # workaround https://github.com/saltstack/salt/issues/31802
1113+ __salt__ ["file.remove" ](name )
11111114 replace = True
11121115
11131116 if __salt__ ["file.file_exists" ](real_name ):
@@ -1382,13 +1385,14 @@ def private_key_managed(
13821385 if file_args .get ("follow_symlinks" , True ):
13831386 real_name = os .path .realpath (name )
13841387 else :
1385- # workaround https://github.com/saltstack/salt/issues/31802
1386- __salt__ ["file.remove" ](name )
1388+ if not __opts__ ["test" ]:
1389+ # workaround https://github.com/saltstack/salt/issues/31802
1390+ __salt__ ["file.remove" ](name )
13871391 replace = True
13881392
13891393 file_exists = __salt__ ["file.file_exists" ](real_name )
13901394
1391- if file_exists and not new :
1395+ if file_exists and not ( new or replace ) :
13921396 try :
13931397 current , current_encoding , _ = x509util .load_privkey (
13941398 real_name , passphrase = passphrase , get_encoding = True
@@ -1445,7 +1449,7 @@ def private_key_managed(
14451449 changes ["keysize" ] = check_keysize
14461450 if encoding != current_encoding :
14471451 changes ["encoding" ] = encoding
1448- elif file_exists and new :
1452+ elif ( file_exists and new ) or replace :
14491453 changes ["replaced" ] = name
14501454 else :
14511455 changes ["created" ] = name
0 commit comments