mitogen-hq / mitogen

Distributed self-replicating programs in Python
https://mitogen.networkgenomics.com/
BSD 3-Clause "New" or "Revised" License
2.34k stars 199 forks source link

`ansible_ssh_password` support #1114

Closed moreati closed 1 month ago

moreati commented 2 months ago

Based on original PR #1107 by @madsi1m, which I accidentally clobbered (see https://github.com/mitogen-hq/mitogen/pull/1107#issuecomment-2328528596).

Fixes #1106.

moreati commented 2 months ago

That was unexpected. The new tests failed across the board https://dev.azure.com/mitogen-hq/mitogen/_build/results?buildId=908, e.g.

TASK [ansible_ssh_password ] ***************************************************
Wednesday 04 September 2024  10:49:43 +0000 (0:00:00.105)       0:07:41.566 *** 
fatal: [target-centos6-1]: UNREACHABLE! => changed=false 
  msg: SSH password is incorrect
  unreachable: true
moreati commented 2 months ago

That was unexpected. The new tests failed across the board

This is probably because ansible_password, and ansible_ssh_pass have legacy support in Ansible. THey predate the modern plugin variables options mechanism that ansible_ssh_password is exposed through, and that Mitogen doesn't properly use (if at all). There are probably existing Mitogen issues and or PRs that touch on this.

See

moreati commented 2 months ago

Survey of attributes/expressions currently used

ansible_mitogen.transport_config.PlayContextSpec

Notes to self

moreati commented 2 months ago

From https://docs.ansible.com/ansible/10/dev_guide/developing_plugins.html#plugin-configuration-documentation-standards

New plugins should define options: in the DOCUMENTATION string of their Python module.

Callback and connection plugins have declared configuration requirements this way since Ansible version 2.4; most plugin types now do the same.

To access the configuration settings in your plugin, use self.get_option(<option_name>). [...] Become, callback, connection and shell plugins are guaranteed to have the engine call set_options(). [...] Vars plugin settings are populated when first accessed (using the self.get_option() or self.get_options() method.


From https://docs.ansible.com/ansible/10/dev_guide/developing_plugins.html#vars-plugins

Playbook constructs like ‘host_vars’ and ‘group_vars’ work using vars plugins.

Most of the work now happens in the get_vars method which is called from the VariableManager when needed.

moreati commented 2 months ago

/AzurePipelines run

azure-pipelines[bot] commented 2 months ago
Azure Pipelines successfully started running 1 pipeline(s).
moreati commented 2 months ago

After a lot of experimentation I think ansible.plugins.AnsiblePlugin.get_option() can be a basis for replacing the variety of techniques in ansible_mitogen.transport_config.PlayContextSpec() et al. Open questions

moreati commented 2 months ago

At the moment it requires ...get_option(..., hostvars=tasks_vars) how expensive is it to provide task_vars every time?

PlayContextSpec.__init__() already calls Connection._get_task_vars(), so there is no additional cost.

moreati commented 2 months ago

How should ansible_mitogen.plugins.* populate DOCUMENTATION options?

This works for the ssh plugin atleast, but it's ugly as sin.

# This specifically has to be from ... import ..., to avoid some *waves hands* post import shuffling
# that ansible does to the sys.modules entry of ansible.plugins.ssh that results in AtrributeError
from ansible.plugins.connection.ssh import DOCUMENTATION as _ansible_ssh_DOCUMENTATION

DOCUMENTATION = """
    name: ...
    ...
    options:
""" + _ansible_ssh_DOCUMENTATION.partition('options:\n')[2]

It doesn't handle

moreati commented 1 month ago

That was a hell of a journey. Some washup items

What is the difference between task vars, and host vars (HostVars) in the Ansible code base?

I think

  1. Task vars are all the variables set when a particular task (or looped task) is running.
  2. Host vars are one source amongst many that feed into task vars.
  3. Some Ansible internal APIs call a parameter hostvars when they mean task vars.

How should ansible_mitogen.transport_config.MitogenViaSpec() be updated/treated?

Worth it's own issue, #1135.