@@ -419,7 +419,28 @@ def __init__(self, connection, play_context, transport, inventory_name):
419419
420420 def _become_option (self , name ):
421421 plugin = self ._connection .become
422- return plugin .get_option (name , self ._task_vars , self ._play_context )
422+ try :
423+ return plugin .get_option (name , self ._task_vars , self ._play_context )
424+ except AttributeError :
425+ # A few ansible_mitogen connection plugins look more like become
426+ # plugins. They don't quite fit Ansible's plugin.get_option() API.
427+ # https://github.com/mitogen-hq/mitogen/issues/1173
428+ fallback_plugins = {'mitogen_doas' , 'mitogen_sudo' , 'mitogen_su' }
429+ if self ._connection .transport not in fallback_plugins :
430+ raise
431+
432+ fallback_options = {
433+ 'become_exe' ,
434+ }
435+ if name not in fallback_options :
436+ raise
437+
438+ LOG .info (
439+ 'Used PlayContext fallback for plugin=%r, option=%r' ,
440+ self ._connection , name ,
441+ )
442+ return getattr (self ._play_context , name )
443+
423444
424445 def _connection_option (self , name ):
425446 try :
@@ -505,15 +526,7 @@ def ssh_args(self):
505526 ]
506527
507528 def become_exe (self ):
508- # In Ansible 2.8, PlayContext.become_exe always has a default value due
509- # to the new options mechanism. Previously it was only set if a value
510- # ("somewhere") had been specified for the task.
511- # For consistency in the tests, here we make older Ansibles behave like
512- # newer Ansibles.
513- exe = self ._play_context .become_exe
514- if exe is None and self ._play_context .become_method == 'sudo' :
515- exe = 'sudo'
516- return exe
529+ return self ._become_option ('become_exe' )
517530
518531 def sudo_args (self ):
519532 return [
0 commit comments