Skip to content

Commit

Permalink
Merge commit '298d28a650a2f154ce3db4bc98495eab964e0e7f' into release-…
Browse files Browse the repository at this point in the history
…v0.3.12
  • Loading branch information
moreati committed Oct 7, 2024
2 parents 0b895c8 + 298d28a commit 644d42f
Show file tree
Hide file tree
Showing 111 changed files with 526 additions and 222 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,15 @@ jobs:
fi
"$PYTHON" -m tox -e "${{ matrix.tox_env }}"
# https://github.com/marketplace/actions/alls-green
check:
if: always()
needs:
- linux
- macos
runs-on: ubuntu-latest
steps:
- uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
27 changes: 6 additions & 21 deletions ansible_mitogen/plugins/connection/mitogen_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,20 @@
import os.path
import sys

from ansible.plugins.connection.ssh import (
DOCUMENTATION as _ansible_ssh_DOCUMENTATION,
)

DOCUMENTATION = """
name: mitogen_ssh
author: David Wilson <[email protected]>
connection: mitogen_ssh
short_description: Connect over SSH via Mitogen
description:
- This connects using an OpenSSH client controlled by the Mitogen for
Ansible extension. It accepts every option the vanilla ssh plugin
accepts.
version_added: "2.5"
options:
ssh_args:
type: str
vars:
- name: ssh_args
- name: ansible_ssh_args
- name: ansible_mitogen_ssh_args
ssh_common_args:
type: str
vars:
- name: ssh_args
- name: ansible_ssh_common_args
- name: ansible_mitogen_ssh_common_args
ssh_extra_args:
type: str
vars:
- name: ssh_args
- name: ansible_ssh_extra_args
- name: ansible_mitogen_ssh_extra_args
"""
""" + _ansible_ssh_DOCUMENTATION.partition('options:\n')[2]

try:
import ansible_mitogen
Expand Down
14 changes: 13 additions & 1 deletion ansible_mitogen/transport_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
__metaclass__ = type

import abc
import logging
import os
import ansible.utils.shlex
import ansible.constants as C
Expand All @@ -74,6 +75,9 @@
import mitogen.core


LOG = logging.getLogger(__name__)


def run_interpreter_discovery_if_necessary(s, task_vars, action, rediscover_python):
"""
Triggers ansible python interpreter discovery if requested.
Expand Down Expand Up @@ -412,6 +416,13 @@ def __init__(self, connection, play_context, transport, inventory_name):
# used to run interpreter discovery
self._action = connection._action

def _connection_option(self, name):
try:
return self._connection.get_option(name, hostvars=self._task_vars)
except KeyError:
LOG.debug('Used PlayContext fallback for option=%r', name)
return getattr(self._play_context, name)

def transport(self):
return self._transport

Expand Down Expand Up @@ -449,7 +460,7 @@ def become_pass(self):
return optional_secret(become_pass)

def password(self):
return optional_secret(self._play_context.password)
return optional_secret(self._connection_option('password'))

def port(self):
return self._play_context.port
Expand Down Expand Up @@ -678,6 +689,7 @@ def become_pass(self):

def password(self):
return optional_secret(
self._host_vars.get('ansible_ssh_password') or
self._host_vars.get('ansible_ssh_pass') or
self._host_vars.get('ansible_password')
)
Expand Down
6 changes: 4 additions & 2 deletions docs/ansible_detailed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ container.
* Intermediary machines cannot use login and become passwords that were
supplied to Ansible interactively. If an intermediary requires a
password, it must be supplied via ``ansible_ssh_pass``,
``ansible_password``, or ``ansible_become_pass`` inventory variables.
``ansible_ssh_password``, ``ansible_password``, or
``ansible_become_pass`` inventory variables.

* Automatic tunnelling of SSH-dependent actions, such as the
``synchronize`` module, is not yet supported. This will be addressed in a
Expand Down Expand Up @@ -1011,7 +1012,8 @@ Like the :ans:conn:`ssh` except connection delegation is supported.
* ``ansible_port``, ``ssh_port``
* ``ansible_ssh_executable``, ``ssh_executable``
* ``ansible_ssh_private_key_file``
* ``ansible_ssh_pass``, ``ansible_password`` (default: assume passwordless)
* ``ansible_ssh_pass``, ``ansible_ssh_password``, ``ansible_password``
(default: assume passwordless)
* ``ssh_args``, ``ssh_common_args``, ``ssh_extra_args``
* ``mitogen_mask_remote_name``: if :data:`True`, mask the identity of the
Ansible controller process on remote machines. To simplify diagnostics,
Expand Down
13 changes: 12 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ To avail of fixes in an unreleased version, please download a ZIP file
`directly from GitHub <https://github.com/mitogen-hq/mitogen/>`_.


v0.3.11 (2024-10-30)
v0.3.11 (2024-10-07)
--------------------

* :gh:issue:`1106` :mod:`ansible_mitogen`: Support for `ansible_ssh_password`
connection variable, and templated SSH connection password.
* :gh:issue:`1136` tests: Improve Ansible fail_msg formatting.
* :gh:issue:`1137` tests: Ignore inventory files of inactive tests & benchmarks
* :gh:issue:`1138` CI: Add re-actors/alls-green GitHub Actions job to simplify
branch protections configuration.


v0.3.11 (2024-09-30)
--------------------

* :gh:issue:`1127` :mod:`mitogen`: Consolidate mitogen backward compatibility
Expand Down
1 change: 1 addition & 0 deletions docs/contributors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ sponsorship and outstanding future-thinking of its early adopters.
<li>Lewis Bellwood &mdash; <em>Happy to be apart of a great project.</em></li>
<li>luto</li>
<li><a href="https://mayeu.me/">Mayeu a.k.a Matthieu Maury</a></li>
<li><a href="https://github.com/madsi1m">Michael D'Silva</a></li>
<li><a href="https://twitter.com/nathanhruby">@nathanhruby</a></li>
<li><a href="https://github.com/opoplawski">Orion Poplawski</a></li>
<li><a href="https://github.com/philfry">Philippe Kueck</a></li>
Expand Down
2 changes: 1 addition & 1 deletion mitogen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


#: Library version as a tuple.
__version__ = (0, 3, 11)
__version__ = (0, 3, 12)


#: This is :data:`False` in slave contexts. Previously it was used to prevent
Expand Down
1 change: 1 addition & 0 deletions tests/ansible/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ host_key_checking = False
[inventory]
any_unparsed_is_failed = true
host_pattern_mismatch = error
ignore_extensions = ~, .bak, .disabled

[callback_profile_tasks]
task_output_limit = 10
Expand Down
14 changes: 14 additions & 0 deletions tests/ansible/hosts/default.hosts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,17 @@ ssh-common-args ansible_host=localhost ansible_user="{{ lookup('pipe', 'whoami')
[issue905:vars]
ansible_ssh_common_args=-o PermitLocalCommand=yes -o LocalCommand="touch {{ ssh_args_canary_file }}"
ssh_args_canary_file=/tmp/ssh_args_{{ inventory_hostname }}

[tt_targets_bare]
tt-bare

[tt_targets_bare:vars]
ansible_host=localhost
ansible_user=mitogen__has_sudo_nopw

[tt_targets_inventory]
tt-password ansible_password="{{ 'has_sudo_nopw_password' | trim }}"

[tt_targets_inventory:vars]
ansible_host=localhost
ansible_user=mitogen__has_sudo_nopw
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion tests/ansible/integration/action/copy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
that:
- item.stat.checksum == item.item.expected_checksum
quiet: true # Avoid spamming stdout with 400 kB of item.item.content
fail_msg: item={{ item }}
fail_msg: |
item={{ item }}
with_items: "{{ stat.results }}"
loop_control:
label: "{{ item.stat.path }}"
Expand Down
15 changes: 10 additions & 5 deletions tests/ansible/integration/action/fixup_perms2__copy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
- assert:
that:
- out.stat.mode in ("0644", "0664")
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: "Copy files from content: arg"
copy:
Expand All @@ -29,7 +30,8 @@
- assert:
that:
- out.stat.mode == "0400"
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: Cleanup local weird mode file
file:
Expand All @@ -55,7 +57,8 @@
- assert:
that:
- out.stat.mode in ("0644", "0664")
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: Copy file with weird mode, preserving mode
copy:
Expand All @@ -69,7 +72,8 @@
- assert:
that:
- out.stat.mode == "1462"
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: Copy file with weird mode, explicit mode
copy:
Expand All @@ -84,7 +88,8 @@
- assert:
that:
- out.stat.mode == "1461"
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: Cleanup
file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
- 'raw.rc == 0'
- 'raw.stdout_lines[-1]|to_text == "2"'
- 'raw.stdout[-1]|to_text == "2"'
fail_msg: raw={{raw}}
fail_msg: |
raw={{ raw }}
- name: Run raw module with sudo
become: true
Expand All @@ -39,6 +40,7 @@
["root\r\n"],
["root"],
)
fail_msg: raw={{raw}}
fail_msg: |
raw={{ raw }}
tags:
- low_level_execute_command
25 changes: 18 additions & 7 deletions tests/ansible/integration/action/make_tmp_path.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@
assert:
that:
- good_temp_path == good_temp_path2
fail_msg: good_temp_path={{good_temp_path}} good_temp_path2={{good_temp_path2}}
fail_msg: |
good_temp_path={{ good_temp_path }}
good_temp_path2={{ good_temp_path2 }}
- name: "Verify different subdir for both tasks"
assert:
that:
- tmp_path.path != tmp_path2.path
fail_msg: tmp_path={{tmp_path}} tmp_path2={{tmp_path2}}
fail_msg: |
tmp_path={{ tmp_path }}
tmp_path2={{ tmp_path2 }}
#
# Verify subdirectory removal.
Expand All @@ -69,7 +73,9 @@
that:
- not stat1.stat.exists
- not stat2.stat.exists
fail_msg: stat1={{stat1}} stat2={{stat2}}
fail_msg: |
stat1={{ stat1 }}
stat2={{ stat2 }}
#
# Verify good directory persistence.
Expand All @@ -84,7 +90,8 @@
assert:
that:
- stat.stat.exists
fail_msg: stat={{stat}}
fail_msg: |
stat={{ stat }}
#
# Write some junk into the temp path.
Expand All @@ -107,7 +114,8 @@
- assert:
that:
- not out.stat.exists
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
#
# root
Expand All @@ -126,7 +134,9 @@
that:
- tmp_path2.path != tmp_path_root.path
- tmp_path2.path|dirname != tmp_path_root.path|dirname
fail_msg: tmp_path_root={{tmp_path_root}} tmp_path2={{tmp_path2}}
fail_msg: |
tmp_path_root={{ tmp_path_root }}
tmp_path2={{ tmp_path2 }}
#
# readonly homedir
Expand Down Expand Up @@ -157,7 +167,8 @@
that:
- out.module_path.startswith(good_temp_path2)
- out.module_tmpdir.startswith(good_temp_path2)
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
tags:
- make_tmp_path
- mitogen_only
18 changes: 12 additions & 6 deletions tests/ansible/integration/action/remote_expand_user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
register: out
- assert:
that: out.result == user_facts.ansible_facts.ansible_user_dir ~ '/foo'
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: "Expand ~/foo with become active. ~ is become_user's home."
action_passthrough:
Expand All @@ -49,7 +50,8 @@
register: out
- assert:
that: out.result == user_facts.ansible_facts.ansible_user_dir ~ '/foo'
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: "Expanding $HOME/foo has no effect."
action_passthrough:
Expand All @@ -60,7 +62,8 @@
register: out
- assert:
that: out.result == '$HOME/foo'
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
# ------------------------

Expand All @@ -73,7 +76,8 @@
register: out
- assert:
that: out.result == user_facts.ansible_facts.ansible_user_dir ~ '/foo'
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: "sudoable; Expand ~/foo with become active. ~ is become_user's home."
action_passthrough:
Expand All @@ -97,7 +101,8 @@
register: out
- assert:
that: out.result == user_facts.ansible_facts.ansible_user_dir ~ '/foo'
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
- name: "sudoable; Expanding $HOME/foo has no effect."
action_passthrough:
Expand All @@ -108,6 +113,7 @@
register: out
- assert:
that: out.result == '$HOME/foo'
fail_msg: out={{out}}
fail_msg: |
out={{ out }}
tags:
- remote_expand_user
Loading

0 comments on commit 644d42f

Please sign in to comment.