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

ansible_ssh_password support #1114

Merged
merged 3 commits into from
Oct 6, 2024
Merged

Conversation

moreati
Copy link
Member

@moreati moreati commented Sep 4, 2024

Based on original PR #1107 by @madsi1m, which I accidentally clobbered (see #1107 (comment)).

Fixes #1106.

@moreati
Copy link
Member Author

moreati commented Sep 4, 2024

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
Copy link
Member Author

moreati commented Sep 5, 2024

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
Copy link
Member Author

moreati commented Sep 6, 2024

Survey of attributes/expressions currently used

ansible_mitogen.transport_config.PlayContextSpec

  • self._play_context.<thing>
  • become_plugin.get_option('<thing>', playcontext=self._play_context)
  • self._connection.get_task_var('ansible_<thing>')
  • C.config.get_config_value("<thing>", plugin_type="connection", plugin_name="ssh", variables=self._task_vars.get("vars", {}))
  • C.config.get_config_value("<thing>", plugin_type="connection", plugin_name="ssh", variables=self._task_vars.get("hostvars", {}).get(self._inventory_name, {}))

Notes to self

  • self._task_vars intialiased at instantiation, vs self._connection.get_task_var() within individual methods
  • self._task_vars.get('vars') vs self._task_vars.get('hostvars')

@moreati
Copy link
Member Author

moreati commented Sep 6, 2024

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 moreati force-pushed the ansible_ssh_password branch 23 times, most recently from 4e82475 to 7b74a22 Compare September 15, 2024 16:02
@moreati
Copy link
Member Author

moreati commented Oct 6, 2024

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.

@moreati moreati marked this pull request as ready for review October 6, 2024 11:48
@moreati moreati force-pushed the ansible_ssh_password branch from 15a1e1f to d9bda21 Compare October 6, 2024 11:56
…h_password

This switches `ansible_mitogen.transport_config.PlayContextSpec.password()` to
Ansible's plugin option framework. As a result
- The relatively recent `ansible_ssh_password` variable is now respected.
- The SSH connection password can be templated and specified as a play
  variable. Task variables will probably also work, but testing was blocked
  by mitogen-hq#1132.

There is a chance this change will cause a regression in another connection
plugin (e.g. mitogen_docker), but nothing turned up in the test suite.
I intend ot migrate other connection configuration to
`ansible_mitogen.transport_config.PlayContextSpec._connect_option()`, the next
candidate is the remote port.

fixes mitogen-hq#1106
@moreati moreati force-pushed the ansible_ssh_password branch from d9bda21 to 551690e Compare October 6, 2024 12:14
@moreati moreati merged commit 17d3f39 into mitogen-hq:master Oct 6, 2024
91 checks passed
@moreati moreati deleted the ansible_ssh_password branch October 6, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ansible_ssh_password missing from mitogen
2 participants