mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
a bunch of updates to connection info and related, to pass down passwords
also now options populate required fields in required order allowing play to override added capture of debug in action plugins when stdout is not json
This commit is contained in:
@@ -38,34 +38,40 @@ class ConnectionInformation:
|
||||
connection/authentication information.
|
||||
'''
|
||||
|
||||
def __init__(self, play=None, options=None):
|
||||
# FIXME: implement the new methodology here for supporting
|
||||
# various different auth escalation methods (becomes, etc.)
|
||||
def __init__(self, play=None, options=None, passwords=None):
|
||||
|
||||
self.connection = C.DEFAULT_TRANSPORT
|
||||
if passwords is None:
|
||||
passwords = {}
|
||||
|
||||
# connection
|
||||
self.connection = None
|
||||
self.remote_addr = None
|
||||
self.remote_user = 'root'
|
||||
self.password = ''
|
||||
self.port = 22
|
||||
self.remote_user = None
|
||||
self.password = passwords.get('conn_pass','')
|
||||
self.port = None
|
||||
self.private_key_file = None
|
||||
|
||||
# privilege escalation
|
||||
self.become = None
|
||||
self.become_method = None
|
||||
self.become_user = None
|
||||
self.become_pass = passwords.get('become_pass','')
|
||||
|
||||
# general flags (should we move out?)
|
||||
self.verbosity = 0
|
||||
self.only_tags = set()
|
||||
self.skip_tags = set()
|
||||
|
||||
# privilege escalation
|
||||
self.become = False
|
||||
self.become_method = C.DEFAULT_BECOME_METHOD
|
||||
self.become_user = ''
|
||||
self.become_pass = ''
|
||||
|
||||
self.no_log = False
|
||||
self.check_mode = False
|
||||
|
||||
#TODO: just pull options setup to above?
|
||||
# set options before play to allow play to override them
|
||||
if options:
|
||||
self.set_options(options)
|
||||
|
||||
if play:
|
||||
self.set_play(play)
|
||||
|
||||
if options:
|
||||
self.set_options(options)
|
||||
|
||||
def __repr__(self):
|
||||
value = "CONNECTION INFO:\n"
|
||||
@@ -84,12 +90,18 @@ class ConnectionInformation:
|
||||
if play.connection:
|
||||
self.connection = play.connection
|
||||
|
||||
self.remote_user = play.remote_user
|
||||
self.password = ''
|
||||
self.port = int(play.port) if play.port else 22
|
||||
self.become = play.become
|
||||
self.become_method = play.become_method
|
||||
self.become_user = play.become_user
|
||||
if play.remote_user:
|
||||
self.remote_user = play.remote_user
|
||||
|
||||
if play.port:
|
||||
self.port = int(play.port)
|
||||
|
||||
if play.become is not None:
|
||||
self.become = play.become
|
||||
if play.become_method:
|
||||
self.become_method = play.become_method
|
||||
if play.become_user:
|
||||
self.become_user = play.become_user
|
||||
self.become_pass = play.become_pass
|
||||
|
||||
# non connection related
|
||||
@@ -103,15 +115,30 @@ class ConnectionInformation:
|
||||
higher precedence than those set on the play or host.
|
||||
'''
|
||||
|
||||
# FIXME: set other values from options here?
|
||||
|
||||
self.verbosity = options.verbosity
|
||||
if options.connection:
|
||||
self.connection = options.connection
|
||||
|
||||
self.remote_user = options.remote_user
|
||||
#if 'port' in options and options.port is not None:
|
||||
# self.port = options.port
|
||||
self.private_key_file = None
|
||||
|
||||
# privilege escalation
|
||||
self.become = options.become
|
||||
self.become_method = options.become_method
|
||||
self.become_user = options.become_user
|
||||
self.become_pass = ''
|
||||
|
||||
# general flags (should we move out?)
|
||||
if options.verbosity:
|
||||
self.verbosity = options.verbosity
|
||||
#if options.no_log:
|
||||
# self.no_log = boolean(options.no_log)
|
||||
if options.check:
|
||||
self.check_mode = boolean(options.check)
|
||||
|
||||
|
||||
|
||||
# get the tag info from options, converting a comma-separated list
|
||||
# of values into a proper list if need be. We check to see if the
|
||||
# options have the attribute, as it is not always added via the CLI
|
||||
|
||||
@@ -36,18 +36,19 @@ class PlaybookExecutor:
|
||||
basis for bin/ansible-playbook operation.
|
||||
'''
|
||||
|
||||
def __init__(self, playbooks, inventory, variable_manager, loader, display, options):
|
||||
def __init__(self, playbooks, inventory, variable_manager, loader, display, options, conn_pass, become_pass):
|
||||
self._playbooks = playbooks
|
||||
self._inventory = inventory
|
||||
self._variable_manager = variable_manager
|
||||
self._loader = loader
|
||||
self._display = display
|
||||
self._options = options
|
||||
self.passwords = {'conn_pass': conn_pass, 'become_pass': become_pass}
|
||||
|
||||
if options.listhosts or options.listtasks or options.listtags:
|
||||
self._tqm = None
|
||||
else:
|
||||
self._tqm = TaskQueueManager(inventory=inventory, callback='default', variable_manager=variable_manager, loader=loader, display=display, options=options)
|
||||
self._tqm = TaskQueueManager(inventory=inventory, callback='default', variable_manager=variable_manager, loader=loader, display=display, options=options, passwords=self.passwords)
|
||||
|
||||
def run(self):
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class TaskQueueManager:
|
||||
which dispatches the Play's tasks to hosts.
|
||||
'''
|
||||
|
||||
def __init__(self, inventory, callback, variable_manager, loader, display, options):
|
||||
def __init__(self, inventory, callback, variable_manager, loader, display, options, passwords):
|
||||
|
||||
self._inventory = inventory
|
||||
self._variable_manager = variable_manager
|
||||
@@ -56,6 +56,7 @@ class TaskQueueManager:
|
||||
self._display = display
|
||||
self._options = options
|
||||
self._stats = AggregateStats()
|
||||
self.passwords = passwords
|
||||
|
||||
# a special flag to help us exit cleanly
|
||||
self._terminated = False
|
||||
@@ -144,7 +145,7 @@ class TaskQueueManager:
|
||||
new_play = play.copy()
|
||||
new_play.post_validate(all_vars, fail_on_undefined=False)
|
||||
|
||||
connection_info = ConnectionInformation(new_play, self._options)
|
||||
connection_info = ConnectionInformation(new_play, self._options, self.passwords)
|
||||
for callback_plugin in self._callback_plugins:
|
||||
if hasattr(callback_plugin, 'set_connection_info'):
|
||||
callback_plugin.set_connection_info(connection_info)
|
||||
|
||||
Reference in New Issue
Block a user