I am generating SSH keys using an Ansible script that works fine with Java 17, However it's not working when using Java 8. The issue seems to be related to the encryption algorithm used in the private key.
When I generate keys using putty-gen it works for both versions however ansible generated keys are only working with newer versions but not older version.
DES-EDE3 encryption (Triple DES) from puttygen works for both Java 8 and 17, while the AES-256 encryption generated by the Ansible script works only with Java 17.
Ansible Script
---
- name: Generate SSH key with passphrase and set permissions
hosts: localhost
connection: local
vars:
ssh_private_key_filepath: "{{ ssh_private_key_filepath }}"
ssh_public_key_filepath: "{{ ssh_public_key_filepath }}"
ssh_passphrase: "{{ ssh_passphrase }}"
tasks:
- name: Generate private key
community.crypto.openssl_privatekey:
path: "{{ ssh_private_key_filepath }}"
type: RSA
size: 4096
passphrase: "{{ ssh_passphrase }}"
cipher: auto
state: present
force: false
register: private_key
- name: Generate public key
community.crypto.openssl_publickey:
path: "{{ ssh_public_key_filepath }}"
privatekey_path: "{{ ssh_private_key_filepath }}"
privatekey_passphrase: "{{ ssh_passphrase }}"
state: present
force: false
format: "OpenSSH"
when: private_key.changed
- name: Set permissions for private key
file:
path: "{{ ssh_private_key_filepath }}"
mode: '400'
- name: Set permissions for public key
file:
path: "{{ ssh_public_key_filepath }}"
mode: '600'
How can I modify my Ansible script or key generation process to make the generated keys compatible with both Java 8 and Java 17 versions.

openssl_privatekeymodule – Generate OpenSSL private keys - Parameter:typethere is no support for DES.