8
8
import tempfile
9
9
10
10
from collections .abc import MutableMapping
11
+ from typing import Any
11
12
12
13
from ansible_runner .config .runner import RunnerConfig
13
14
from ansible_runner .utils import isinventory , isplaybook
14
15
15
16
16
17
def dump_artifacts (config : RunnerConfig ) -> None :
17
18
"""Introspect the arguments and dump objects to disk"""
19
+ private_data_dir = config .private_data_dir or ""
20
+
18
21
if config .role :
19
- role = {'name' : config .role }
22
+ role : dict [ str , Any ] = {'name' : config .role }
20
23
if config .role_vars :
21
24
role ['vars' ] = config .role_vars
22
25
23
26
hosts = config .host_pattern or 'all'
24
- play = [{'hosts' : hosts , 'roles' : [role ]}]
27
+ play : list [ dict [ str , Any ]] = [{'hosts' : hosts , 'roles' : [role ]}]
25
28
26
29
if config .role_skip_facts :
27
30
play [0 ]['gather_facts' ] = False
@@ -33,9 +36,9 @@ def dump_artifacts(config: RunnerConfig) -> None:
33
36
34
37
roles_path = config .roles_path
35
38
if not roles_path :
36
- roles_path = os .path .join (config . private_data_dir , 'roles' )
39
+ roles_path = os .path .join (private_data_dir , 'roles' )
37
40
else :
38
- roles_path += f":{ os .path .join (config . private_data_dir , 'roles' )} "
41
+ roles_path += f":{ os .path .join (private_data_dir , 'roles' )} "
39
42
40
43
config .envvars ['ANSIBLE_ROLES_PATH' ] = roles_path
41
44
@@ -46,12 +49,12 @@ def dump_artifacts(config: RunnerConfig) -> None:
46
49
playbook = [playbook ]
47
50
48
51
if isplaybook (playbook ):
49
- path = os .path .join (config . private_data_dir , 'project' )
52
+ path = os .path .join (private_data_dir , 'project' )
50
53
config .playbook = dump_artifact (json .dumps (playbook ), path , 'main.json' )
51
54
52
55
obj = config .inventory
53
56
if obj and isinventory (obj ):
54
- path = os .path .join (config . private_data_dir , 'inventory' )
57
+ path = os .path .join (private_data_dir , 'inventory' )
55
58
if isinstance (obj , MutableMapping ):
56
59
config .inventory = dump_artifact (json .dumps (obj ), path , 'hosts.json' )
57
60
elif isinstance (obj , str ):
@@ -65,14 +68,14 @@ def dump_artifacts(config: RunnerConfig) -> None:
65
68
if not config .suppress_env_files :
66
69
for key in ('envvars' , 'extravars' , 'passwords' , 'settings' ):
67
70
obj = getattr (config , key , None )
68
- if obj and not os .path .exists (os .path .join (config . private_data_dir , 'env' , key )):
69
- path = os .path .join (config . private_data_dir , 'env' )
71
+ if obj and not os .path .exists (os .path .join (private_data_dir , 'env' , key )):
72
+ path = os .path .join (private_data_dir , 'env' )
70
73
dump_artifact (json .dumps (obj ), path , key )
71
74
72
75
for key in ('ssh_key' , 'cmdline' ):
73
76
obj = getattr (config , key , None )
74
- if obj and not os .path .exists (os .path .join (config . private_data_dir , 'env' , key )):
75
- path = os .path .join (config . private_data_dir , 'env' )
77
+ if obj and not os .path .exists (os .path .join (private_data_dir , 'env' , key )):
78
+ path = os .path .join (private_data_dir , 'env' )
76
79
dump_artifact (obj , path , key )
77
80
78
81
0 commit comments