Skip to content

Commit 5b750ff

Browse files
zolloJoe Zollo
andauthored
Adds Support for Shell Type Instance Param to Delegated Driver (#3932)
* add parsing for shell type * fix a typo * simplified ansible_connection_options method * fix spelling issue --------- Co-authored-by: Joe Zollo <[email protected]>
1 parent 9e07f85 commit 5b750ff

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

src/molecule/driver/delegated.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class Delegated(Driver):
5454
instance: instance_name
5555
port: ssh_port_as_string
5656
user: ssh_user
57+
shell_type: sh
5758
password: ssh_password # mutually exclusive with identity_file
5859
become_method: valid_ansible_become_method # optional
5960
become_pass: password_if_required # optional
@@ -64,6 +65,7 @@ class Delegated(Driver):
6465
port: winrm_port_as_string
6566
user: winrm_user
6667
password: winrm_password
68+
shell_type: powershell
6769
winrm_transport: ntlm/credssp/kerberos
6870
winrm_cert_pem: <path to the credssp public certificate key>
6971
winrm_cert_key_pem: <path to the credssp private certificate key>
@@ -194,19 +196,30 @@ def login_options(self, instance_name):
194196
return {"instance": instance_name}
195197

196198
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+
]
197210
if self.managed:
198211
try:
199212
d = self._get_instance_config(instance_name)
200213
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+
201219
conn_dict["ansible_user"] = d.get("user")
202220
conn_dict["ansible_host"] = d.get("address")
203221
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+
210223
if d.get("identity_file", None):
211224
conn_dict["ansible_private_key_file"] = d.get("identity_file")
212225
conn_dict["ansible_ssh_common_args"] = " ".join(
@@ -217,18 +230,6 @@ def ansible_connection_options(self, instance_name):
217230
# Based on testinfra documentation, ansible password must be passed via ansible_ssh_pass
218231
# issue to fix this can be found https://github.com/pytest-dev/pytest-testinfra/issues/580
219232
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-
)
232233

233234
return conn_dict
234235

0 commit comments

Comments
 (0)