Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
moreati committed Oct 7, 2024
1 parent 45ab534 commit 8e400b0
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ansible_mitogen/transport_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def password(self):
return optional_secret(self._connection_option('password'))

def port(self):
return self._play_context.port
return self._connection_option('port')

def python_path(self, rediscover_python=False):
s = self._connection.get_task_var('ansible_python_interpreter')
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ To avail of fixes in an unreleased version, please download a ZIP file
In Progress (unreleased)
------------------------

* :gh:issue:`978` :mod:`ansible_mitogen`: Support templated Ansible SSH port.
* :gh:issue:`1138` CI: Complete migration from Azure DevOps Pipelines to
GitHub Actions

Expand Down
1 change: 1 addition & 0 deletions tests/ansible/hosts/default.hosts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ansible_user=mitogen__has_sudo_nopw

[tt_targets_inventory]
tt-password ansible_password="{{ 'has_sudo_nopw_password' | trim }}"
tt-port ansible_password=has_sudo_nopw_password ansible_port="{{ 22 | int }}"

[tt_targets_inventory:vars]
ansible_host=localhost
Expand Down
11 changes: 11 additions & 0 deletions tests/ansible/integration/_expected_ssh_port.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ansible removed its default SSH port in May 2021, defering to the SSH
# implementation.
# https://github.com/ansible/ansible/commit/45618a6f3856f7332df8afe4adc40d85649a70da

- set_fact:
expected_ssh_port: null
when: ansible_version.full is version('2.11.1', '>=', strict=True)

- set_fact:
expected_ssh_port: 22
when: ansible_version.full is version('2.11.1', '<', strict=True)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
gather_facts: no
tasks:
- include_tasks: ../_mitogen_only.yml
- include_tasks: ../_expected_ssh_port.yml

- meta: end_play
when:
Expand Down Expand Up @@ -66,7 +67,7 @@
'keepalive_interval': 30,
'keepalive_count': 10,
'password': null,
'port': null,
'port': '{{ expected_ssh_port }}',
'python_path': ['python3000'],
'remote_name': null,
'ssh_args': [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
- hosts: cd-normal
tasks:
- include_tasks: ../_mitogen_only.yml
- include_tasks: ../_expected_ssh_port.yml
- mitogen_get_stack:
delegate_to: cd-alias
register: out
Expand All @@ -72,7 +73,7 @@
'keepalive_interval': 30,
'keepalive_count': 10,
'password': null,
'port': null,
'port': '{{ expected_ssh_port }}',
"python_path": ["python3000"],
'remote_name': null,
'ssh_args': [
Expand All @@ -98,6 +99,7 @@
- hosts: cd-alias
tasks:
- include_tasks: ../_mitogen_only.yml
- include_tasks: ../_expected_ssh_port.yml
- mitogen_get_stack:
register: out
- assert_equal:
Expand All @@ -114,7 +116,7 @@
'keepalive_interval': 30,
'keepalive_count': 10,
'password': null,
'port': null,
'port': '{{ expected_ssh_port }}',
"python_path": ["python3000"],
'remote_name': null,
'ssh_args': [
Expand All @@ -140,6 +142,7 @@
- hosts: cd-normal-normal
tasks:
- include_tasks: ../_mitogen_only.yml
- include_tasks: ../_expected_ssh_port.yml
- mitogen_get_stack:
register: out
- assert_equal:
Expand Down Expand Up @@ -167,7 +170,7 @@
'keepalive_interval': 30,
'keepalive_count': 10,
'password': null,
'port': null,
'port': '{{ expected_ssh_port }}',
"python_path": ["python3000"],
'remote_name': null,
'ssh_args': [
Expand All @@ -193,6 +196,7 @@
- hosts: cd-normal-alias
tasks:
- include_tasks: ../_mitogen_only.yml
- include_tasks: ../_expected_ssh_port.yml
- mitogen_get_stack:
register: out
- assert_equal:
Expand Down Expand Up @@ -237,7 +241,7 @@
'keepalive_interval': 30,
'keepalive_count': 10,
'password': null,
'port': null,
'port': '{{ expected_ssh_port }}',
"python_path": ["python3000"],
'remote_name': null,
'ssh_args': [
Expand All @@ -262,6 +266,7 @@
- hosts: cd-newuser-normal-normal
tasks:
- include_tasks: ../_mitogen_only.yml
- include_tasks: ../_expected_ssh_port.yml
- mitogen_get_stack:
register: out
- assert_equal:
Expand Down Expand Up @@ -289,7 +294,7 @@
'keepalive_interval': 30,
'keepalive_count': 10,
'password': null,
'port': null,
'port': '{{ expected_ssh_port }}',
"python_path": ["python3000"],
'remote_name': null,
'ssh_args': [
Expand All @@ -315,6 +320,7 @@
- hosts: cd-newuser-normal-normal
tasks:
- include_tasks: ../_mitogen_only.yml
- include_tasks: ../_expected_ssh_port.yml
- mitogen_get_stack:
delegate_to: cd-alias
register: out
Expand All @@ -332,7 +338,7 @@
'keepalive_interval': 30,
'keepalive_count': 10,
'password': null,
'port': null,
'port': '{{ expected_ssh_port }}',
"python_path": ["python3000"],
'remote_name': null,
'ssh_args': [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
gather_facts: false
vars:
ansible_password: "{{ 'has_sudo_nopw_password' | trim }}"
ansible_port: "{{ hostvars[groups['test-targets'][0]].ansible_port | default(22) }}"

tasks:
- meta: reset_connection
Expand Down
12 changes: 8 additions & 4 deletions tests/ansible/integration/transport_config/port.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
hosts: tc-port-unset
tasks:
- include_tasks: ../_mitogen_only.yml
- include_tasks: ../_expected_ssh_port.yml
- {mitogen_get_stack: {}, register: out}
- assert:
that:
- out.result|length == 1
- out.result[0].method == "ssh"
- out.result[0].kwargs.port == None
- out.result[0].kwargs.port == expected_ssh_port
fail_msg: |
out={{ out }}
tags:
Expand Down Expand Up @@ -54,14 +55,15 @@
vars: {mitogen_via: tc-port-explicit-ssh}
tasks:
- include_tasks: ../_mitogen_only.yml
- include_tasks: ../_expected_ssh_port.yml
- {mitogen_get_stack: {}, register: out}
- assert:
that:
- out.result|length == 2
- out.result[0].method == "ssh"
- out.result[0].kwargs.port == 4321
- out.result[1].method == "ssh"
- out.result[1].kwargs.port == None
- out.result[0].kwargs.port == expected_ssh_port
fail_msg: |
out={{ out }}
tags:
Expand All @@ -86,14 +88,15 @@
vars: {mitogen_via: tc-port-explicit-port}
tasks:
- include_tasks: ../_mitogen_only.yml
- include_tasks: ../_expected_ssh_port.yml
- {mitogen_get_stack: {}, register: out}
- assert:
that:
- out.result|length == 2
- out.result[0].method == "ssh"
- out.result[0].kwargs.port == 1234
- out.result[1].method == "ssh"
- out.result[1].kwargs.port == None
- out.result[0].kwargs.port == expected_ssh_port
fail_msg: |
out={{ out }}
tags:
Expand All @@ -119,14 +122,15 @@
vars: {mitogen_via: tc-port-both}
tasks:
- include_tasks: ../_mitogen_only.yml
- include_tasks: ../_expected_ssh_port.yml
- {mitogen_get_stack: {}, register: out}
- assert:
that:
- out.result|length == 2
- out.result[0].method == "ssh"
- out.result[0].kwargs.port == 1532
- out.result[1].method == "ssh"
- out.result[1].kwargs.port == None
- out.result[0].kwargs.port == expected_ssh_port
fail_msg: |
out={{ out }}
tags:
Expand Down
1 change: 1 addition & 0 deletions tests/ansible/templates/test-targets.j2
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ ansible_user=mitogen__has_sudo_nopw

[tt_targets_inventory]
tt-password ansible_password="{{ '{{' }} 'has_sudo_nopw_password' | trim {{ '}}' }}" ansible_port={{ tt.port }}
tt-port ansible_password=has_sudo_nopw_password ansible_port="{{ '{{' }} {{ tt.port }} | int {{ '}}' }}"

[tt_targets_inventory:vars]
ansible_host={{ tt.hostname }}
Expand Down

0 comments on commit 8e400b0

Please sign in to comment.