Skip to content

Commit

Permalink
src/molecule/driver/delegated.py: Fix connection plugin name setting (#…
Browse files Browse the repository at this point in the history
…3957)

In ansible_connection_options(), when setting connection plugin name,
the code does:

                for i in instance_params:
                     if d.get(i[0], i[1]):
                         conn_dict["ansible_" + i[0]] = d.get(i[0])

Looking at instance_params, for the connection, there's a default value
neither None nor False, leading to the the being true and setting
ansible_connection to d.get(i[0]), which may not be defined. In this
case, this will lead to ansible_connection being set to None. This will
lead to troubles. For instance, when using 'meta: reset_connection',
ansible in _execute_meta() will call
plugin_loader.connection_loader.get() with first param being None,
leading to :
ERROR! Unexpected Exception, this is probably a bug: 'NoneType' object
has no attribute 'startswith'

So, ensure that the default value is set when setting conn_dict.

Fixes: 5b750ff ("Adds Support for Shell
Type Instance Param to Delegated Driver")

Signed-off-by: Arnaud Patard <[email protected]>
Co-authored-by: Sorin Sbarnea <[email protected]>
  • Loading branch information
apatard and ssbarnea authored Jul 11, 2023
1 parent 88be3b6 commit 99a95f8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/molecule/driver/delegated.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def ansible_connection_options(self, instance_name):
# Check if optional mappable params are in the instance config
for i in instance_params:
if d.get(i[0], i[1]):
conn_dict["ansible_" + i[0]] = d.get(i[0])
conn_dict["ansible_" + i[0]] = d.get(i[0], i[1])

conn_dict["ansible_user"] = d.get("user")
conn_dict["ansible_host"] = d.get("address")
Expand Down

0 comments on commit 99a95f8

Please sign in to comment.