mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 22:51:23 -07:00
Moving ConnectionInformation -> PlayContext
Also making PlayContext a child class of the Playbook Base class, which gives it access to all of the FieldAttribute code to ensure field values are correctly typed after post_validation Fixes #11381
This commit is contained in:
parent
919aaa5c42
commit
e64989beb4
36 changed files with 477 additions and 459 deletions
|
@ -27,7 +27,6 @@ import time
|
|||
|
||||
from ansible import constants as C
|
||||
from ansible.errors import AnsibleError, AnsibleParserError
|
||||
from ansible.executor.connection_info import ConnectionInformation
|
||||
from ansible.playbook.conditional import Conditional
|
||||
from ansible.playbook.task import Task
|
||||
from ansible.plugins import lookup_loader, connection_loader, action_loader
|
||||
|
@ -52,11 +51,11 @@ class TaskExecutor:
|
|||
# the module
|
||||
SQUASH_ACTIONS = frozenset(('apt', 'yum', 'pkgng', 'zypper', 'dnf'))
|
||||
|
||||
def __init__(self, host, task, job_vars, connection_info, new_stdin, loader, shared_loader_obj):
|
||||
def __init__(self, host, task, job_vars, play_context, new_stdin, loader, shared_loader_obj):
|
||||
self._host = host
|
||||
self._task = task
|
||||
self._job_vars = job_vars
|
||||
self._connection_info = connection_info
|
||||
self._play_context = play_context
|
||||
self._new_stdin = new_stdin
|
||||
self._loader = loader
|
||||
self._shared_loader_obj = shared_loader_obj
|
||||
|
@ -208,11 +207,11 @@ class TaskExecutor:
|
|||
|
||||
# fields set from the play/task may be based on variables, so we have to
|
||||
# do the same kind of post validation step on it here before we use it.
|
||||
self._connection_info.post_validate(templar=templar)
|
||||
self._play_context.post_validate(templar=templar)
|
||||
|
||||
# now that the connection information is finalized, we can add 'magic'
|
||||
# now that the play context is finalized, we can add 'magic'
|
||||
# variables to the variable dictionary
|
||||
self._connection_info.update_vars(variables)
|
||||
self._play_context.update_vars(variables)
|
||||
|
||||
# Evaluate the conditional (if any) for this task, which we do before running
|
||||
# the final task post-validation. We do this before the post validation due to
|
||||
|
@ -362,7 +361,7 @@ class TaskExecutor:
|
|||
'normal',
|
||||
task=async_task,
|
||||
connection=self._connection,
|
||||
connection_info=self._connection_info,
|
||||
play_context=self._play_context,
|
||||
loader=self._loader,
|
||||
templar=templar,
|
||||
shared_loader_obj=self._shared_loader_obj,
|
||||
|
@ -392,16 +391,16 @@ class TaskExecutor:
|
|||
# FIXME: delegate_to calculation should be done here
|
||||
# FIXME: calculation of connection params/auth stuff should be done here
|
||||
|
||||
if not self._connection_info.remote_addr:
|
||||
self._connection_info.remote_addr = self._host.ipv4_address
|
||||
if not self._play_context.remote_addr:
|
||||
self._play_context.remote_addr = self._host.ipv4_address
|
||||
|
||||
if self._task.delegate_to is not None:
|
||||
self._compute_delegate(variables)
|
||||
|
||||
conn_type = self._connection_info.connection
|
||||
conn_type = self._play_context.connection
|
||||
if conn_type == 'smart':
|
||||
conn_type = 'ssh'
|
||||
if sys.platform.startswith('darwin') and self._connection_info.password:
|
||||
if sys.platform.startswith('darwin') and self._play_context.password:
|
||||
# due to a current bug in sshpass on OSX, which can trigger
|
||||
# a kernel panic even for non-privileged users, we revert to
|
||||
# paramiko on that OS when a SSH password is specified
|
||||
|
@ -413,7 +412,7 @@ class TaskExecutor:
|
|||
if "Bad configuration option" in err:
|
||||
conn_type = "paramiko"
|
||||
|
||||
connection = connection_loader.get(conn_type, self._connection_info, self._new_stdin)
|
||||
connection = connection_loader.get(conn_type, self._play_context, self._new_stdin)
|
||||
if not connection:
|
||||
raise AnsibleError("the connection plugin '%s' was not found" % conn_type)
|
||||
|
||||
|
@ -437,7 +436,7 @@ class TaskExecutor:
|
|||
handler_name,
|
||||
task=self._task,
|
||||
connection=connection,
|
||||
connection_info=self._connection_info,
|
||||
play_context=self._play_context,
|
||||
loader=self._loader,
|
||||
templar=templar,
|
||||
shared_loader_obj=self._shared_loader_obj,
|
||||
|
@ -458,16 +457,16 @@ class TaskExecutor:
|
|||
this_info = {}
|
||||
|
||||
# get the real ssh_address for the delegate and allow ansible_ssh_host to be templated
|
||||
#self._connection_info.remote_user = self._compute_delegate_user(self.delegate_to, delegate['inject'])
|
||||
self._connection_info.remote_addr = this_info.get('ansible_ssh_host', self._task.delegate_to)
|
||||
self._connection_info.port = this_info.get('ansible_ssh_port', self._connection_info.port)
|
||||
self._connection_info.password = this_info.get('ansible_ssh_pass', self._connection_info.password)
|
||||
self._connection_info.private_key_file = this_info.get('ansible_ssh_private_key_file', self._connection_info.private_key_file)
|
||||
self._connection_info.connection = this_info.get('ansible_connection', C.DEFAULT_TRANSPORT)
|
||||
self._connection_info.become_pass = this_info.get('ansible_sudo_pass', self._connection_info.become_pass)
|
||||
#self._play_context.remote_user = self._compute_delegate_user(self.delegate_to, delegate['inject'])
|
||||
self._play_context.remote_addr = this_info.get('ansible_ssh_host', self._task.delegate_to)
|
||||
self._play_context.port = this_info.get('ansible_ssh_port', self._play_context.port)
|
||||
self._play_context.password = this_info.get('ansible_ssh_pass', self._play_context.password)
|
||||
self._play_context.private_key_file = this_info.get('ansible_ssh_private_key_file', self._play_context.private_key_file)
|
||||
self._play_context.connection = this_info.get('ansible_connection', C.DEFAULT_TRANSPORT)
|
||||
self._play_context.become_pass = this_info.get('ansible_sudo_pass', self._play_context.become_pass)
|
||||
|
||||
if self._connection_info.remote_addr in ('127.0.0.1', 'localhost'):
|
||||
self._connection_info.connection = 'local'
|
||||
if self._play_context.remote_addr in ('127.0.0.1', 'localhost'):
|
||||
self._play_context.connection = 'local'
|
||||
|
||||
# Last chance to get private_key_file from global variables.
|
||||
# this is useful if delegated host is not defined in the inventory
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue