@@ -54,6 +54,7 @@ class Delegated(Driver):
54
54
instance: instance_name
55
55
port: ssh_port_as_string
56
56
user: ssh_user
57
+ shell_type: sh
57
58
password: ssh_password # mutually exclusive with identity_file
58
59
become_method: valid_ansible_become_method # optional
59
60
become_pass: password_if_required # optional
@@ -64,6 +65,7 @@ class Delegated(Driver):
64
65
port: winrm_port_as_string
65
66
user: winrm_user
66
67
password: winrm_password
68
+ shell_type: powershell
67
69
winrm_transport: ntlm/credssp/kerberos
68
70
winrm_cert_pem: <path to the credssp public certificate key>
69
71
winrm_cert_key_pem: <path to the credssp private certificate key>
@@ -194,19 +196,30 @@ def login_options(self, instance_name):
194
196
return {"instance" : instance_name }
195
197
196
198
def ansible_connection_options (self , instance_name ):
199
+ # list of tuples describing mappable instance params and default values
200
+ instance_params = [
201
+ ("become_pass" , None ),
202
+ ("become_method" , False ),
203
+ ("winrm_transport" , None ),
204
+ ("winrm_cert_pem" , None ),
205
+ ("winrm_cert_key_pem" , None ),
206
+ ("winrm_server_cert_validation" , None ),
207
+ ("shell_type" , None ),
208
+ ("connection" , "smart" ),
209
+ ]
197
210
if self .managed :
198
211
try :
199
212
d = self ._get_instance_config (instance_name )
200
213
conn_dict = {}
214
+ # Check if optional mappable params are in the instance config
215
+ for i in instance_params :
216
+ if d .get (i [0 ], i [1 ]):
217
+ conn_dict ["ansible_" + i [0 ]] = d .get (i [0 ])
218
+
201
219
conn_dict ["ansible_user" ] = d .get ("user" )
202
220
conn_dict ["ansible_host" ] = d .get ("address" )
203
221
conn_dict ["ansible_port" ] = d .get ("port" )
204
- if d .get ("connection" , None ):
205
- conn_dict ["ansible_connection" ] = d .get ("connection" , "smart" )
206
- if d .get ("become_method" , False ):
207
- conn_dict ["ansible_become_method" ] = d .get ("become_method" )
208
- if d .get ("become_pass" , None ):
209
- conn_dict ["ansible_become_pass" ] = d .get ("become_pass" )
222
+
210
223
if d .get ("identity_file" , None ):
211
224
conn_dict ["ansible_private_key_file" ] = d .get ("identity_file" )
212
225
conn_dict ["ansible_ssh_common_args" ] = " " .join (
@@ -217,18 +230,6 @@ def ansible_connection_options(self, instance_name):
217
230
# Based on testinfra documentation, ansible password must be passed via ansible_ssh_pass
218
231
# issue to fix this can be found https://github.com/pytest-dev/pytest-testinfra/issues/580
219
232
conn_dict ["ansible_ssh_pass" ] = d .get ("password" )
220
- if d .get ("winrm_transport" , None ):
221
- conn_dict ["ansible_winrm_transport" ] = d .get ("winrm_transport" )
222
- if d .get ("winrm_cert_pem" , None ):
223
- conn_dict ["ansible_winrm_cert_pem" ] = d .get ("winrm_cert_pem" )
224
- if d .get ("winrm_cert_key_pem" , None ):
225
- conn_dict ["ansible_winrm_cert_key_pem" ] = d .get (
226
- "winrm_cert_key_pem" ,
227
- )
228
- if d .get ("winrm_server_cert_validation" , None ):
229
- conn_dict ["ansible_winrm_server_cert_validation" ] = d .get (
230
- "winrm_server_cert_validation" ,
231
- )
232
233
233
234
return conn_dict
234
235
0 commit comments