Skip to content

Commit 9189c01

Browse files
authored
Merge pull request #1181 from moreati/issue1083-private_key_file
ansible_mitogen: Templated SSH private key file
2 parents 5895cca + c7df5c9 commit 9189c01

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

ansible_mitogen/transport_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def candidates():
508508
return boolean(val)
509509

510510
def private_key_file(self):
511-
return self._play_context.private_key_file
511+
return self._connection_option('private_key_file')
512512

513513
def ssh_executable(self):
514514
return self._connection_option('ssh_executable')

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ In progress (unreleased)
2323

2424
* :gh:issue:`1182` CI: Fix incorrect world readable/writable file permissions
2525
on SSH key ``mitogen__has_sudo_pubkey.key`` during Ansible tests.
26+
* :gh:issue:`1083` :mod:`ansible_mitogen`: Templated SSH private key file
27+
(e.g. ``ansible_private_key_file``).
2628

2729

2830
v0.3.16 (2024-11-05)

tests/ansible/hosts/default.hosts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ ansible_user="{{ lookup('pipe', 'whoami') }}"
4545
[tt_targets_inventory]
4646
tt-password ansible_password="{{ 'has_sudo_nopw_password' | trim }}" ansible_user=mitogen__has_sudo_nopw
4747
tt-port ansible_password=has_sudo_nopw_password ansible_port="{{ 22 | int }}" ansible_user=mitogen__has_sudo_nopw
48+
tt-private-key-file ansible_private_key_file="{{ git_basedir }}/tests/data/docker/mitogen__has_sudo_pubkey.key" ansible_user=mitogen__has_sudo_pubkey
4849
tt-remote-user ansible_password=has_sudo_nopw_password ansible_user="{{ 'mitogen__has_sudo_nopw' | trim }}"
4950
tt-ssh-executable ansible_password=has_sudo_nopw_password ansible_ssh_executable="{{ 'ssh' | trim }}" ansible_user=mitogen__has_sudo_nopw
5051

tests/ansible/integration/ssh/templated_by_play_taskvar.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,24 @@
99

1010
tasks:
1111
- meta: reset_connection
12-
- name: Templated variables in play
12+
- name: Templated variables in play, password authentication
13+
ping:
14+
15+
- name: integration/ssh/templated_by_play_taskvar.yml
16+
hosts: tt_targets_bare
17+
gather_facts: false
18+
vars:
19+
ansible_private_key_file: "{{ git_basedir }}/tests/data/docker/mitogen__has_sudo_pubkey.key"
20+
ansible_port: "{{ hostvars[groups['test-targets'][0]].ansible_port | default(22) }}"
21+
ansible_ssh_executable: "{{ 'ssh' | trim }}"
22+
ansible_user: "{{ 'mitogen__has_sudo_pubkey' | trim }}"
23+
24+
tasks:
25+
- meta: end_play
26+
when:
27+
# https://github.com/ansible/ansible/issues/84238
28+
- not is_mitogen
29+
- ansible_version.full is version('2.19', '<', strict=True)
30+
- meta: reset_connection
31+
- name: Templated variables in play, key authentication
1332
ping:

tests/ansible/templates/test-targets.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ ansible_user=mitogen__has_sudo_nopw
7373
[tt_targets_inventory]
7474
tt-password ansible_password="{{ '{{' }} 'has_sudo_nopw_password' | trim {{ '}}' }}" ansible_port={{ tt.port }} ansible_user=mitogen__has_sudo_nopw
7575
tt-port ansible_password=has_sudo_nopw_password ansible_port="{{ '{{' }} {{ tt.port }} | int {{ '}}' }}" ansible_user=mitogen__has_sudo_nopw
76+
tt-private-key-file ansible_port={{ tt.port }} ansible_private_key_file="{{ '{{' }} git_basedir {{ '}}' }}/tests/data/docker/mitogen__has_sudo_pubkey.key" ansible_user=mitogen__has_sudo_pubkey
7677
tt-remote-user ansible_password=has_sudo_nopw_password ansible_port={{ tt.port }} ansible_user="{{ '{{' }} 'mitogen__has_sudo_nopw' | trim {{ '}}' }}"
7778
tt-ssh-executable ansible_password=has_sudo_nopw_password ansible_port={{ tt.port }} ansible_ssh_executable="{{ '{{' }} 'ssh' | trim {{ '}}' }}" ansible_user=mitogen__has_sudo_nopw
7879

0 commit comments

Comments
 (0)