Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connection plugin name setting #3957

Merged
merged 2 commits into from
Jul 11, 2023

Conversation

apatard
Copy link
Contributor

@apatard apatard commented Jul 4, 2023

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")

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]>
@apatard apatard requested review from a team as code owners July 4, 2023 15:40
@ssbarnea ssbarnea added the bug label Jul 11, 2023
@ssbarnea
Copy link
Member

@apatard Do you think you could show me a minimal example that reproduces the bug? I want to include it in the test suite so we are sure we fix it properly.

@apatard
Copy link
Contributor Author

apatard commented Jul 11, 2023

took me some time to find a way to reproduce but here it is:
https://gist.github.com/apatard/5ac88bbebc3409c3b896597a4621d1f6
(it's a shell script which will create the reproducer)
Nevertheless, I'm not sure how to convert it into a proper test case

@ssbarnea ssbarnea merged commit 99a95f8 into ansible:main Jul 11, 2023
@ssbarnea ssbarnea changed the title src/molecule/driver/delegated.py: Fix connection plugin name setting Fix connection plugin name setting Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants