Skip to content

Comments

role:ssh use keychain#136

Merged
thaim merged 5 commits intomasterfrom
ssh-keychain
Jul 27, 2025
Merged

role:ssh use keychain#136
thaim merged 5 commits intomasterfrom
ssh-keychain

Conversation

@thaim
Copy link
Owner

@thaim thaim commented Jul 27, 2025

No description provided.

@thaim thaim requested a review from Copilot July 27, 2025 08:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds keychain support to the SSH role for better SSH key management across different operating systems. Keychain is a front-end to ssh-agent that helps manage SSH keys persistently across shell sessions.

  • Installs keychain package on Debian-based Linux systems
  • Configures shell integration for keychain on Linux and native macOS keychain support
  • Updates SSH client configuration to automatically add keys to agent and use keychain features

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
roles/ssh/tasks/main.yml Adds keychain installation and shell configuration tasks, updates SSH config block
roles/ssh/tasks/install_Debian.yml Implements keychain package installation for Debian/Ubuntu systems
roles/ssh/tasks/configure_shell.yml Configures shell RC files for keychain integration on Linux and macOS
playbook-devel.yml Adds SSH role to the development playbook
Comments suppressed due to low confidence (1)

roles/ssh/tasks/main.yml:5

  • The task name mentions 'Linux only' but the when condition only checks for Debian family. Consider renaming to 'Install keychain (Debian/Ubuntu)' to be more accurate.
- name: Install keychain (Linux only)


- name: Install keychain (Linux only)
ansible.builtin.include_tasks: "install_{{ ansible_os_family }}.yml"
when: ansible_os_family == 'Debian'
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition only supports Debian family systems, but other Linux distributions like RedHat, SUSE, or Arch might also benefit from keychain. Consider expanding support or making the limitation clearer in documentation.

Suggested change
when: ansible_os_family == 'Debian'
when: ansible_os_family in ['Debian', 'RedHat', 'Suse', 'Arch']

Copilot uses AI. Check for mistakes.

- name: Get shell configuration
ansible.builtin.set_fact:
shell_info: "{{ ansible_user_shell | shell_config }}"
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'shell_config' filter is used but may not be a standard Ansible filter. This could cause the task to fail if the filter is not defined or available.

Suggested change
shell_info: "{{ ansible_user_shell | shell_config }}"
shell_info: >
{{
{
'/bin/bash': {'rc_file': '.bashrc'},
'/bin/zsh': {'rc_file': '.zshrc'}
}[ansible_user_shell] | default({'rc_file': '.profile'})
}}

Copilot uses AI. Check for mistakes.

- name: Setup keychain for SSH keys (Linux)
ansible.builtin.lineinfile:
path: "{{ ansible_user_dir }}/{{ shell_info.rc_file }}"
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable 'ansible_user_dir' is used but this is not a standard Ansible fact. Consider using 'ansible_env.HOME' instead, which is the standard way to reference the user's home directory.

Suggested change
path: "{{ ansible_user_dir }}/{{ shell_info.rc_file }}"
path: "{{ ansible_env.HOME }}/{{ shell_info.rc_file }}"

Copilot uses AI. Check for mistakes.

- name: Setup SSH agent for keychain (macOS)
ansible.builtin.lineinfile:
path: "{{ ansible_user_dir }}/{{ shell_info.rc_file }}"
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as above - 'ansible_user_dir' should likely be 'ansible_env.HOME' to reference the user's home directory correctly.

Suggested change
path: "{{ ansible_user_dir }}/{{ shell_info.rc_file }}"
path: "{{ ansible_env.HOME }}/{{ shell_info.rc_file }}"

Copilot uses AI. Check for mistakes.
- name: Setup keychain for SSH keys (Linux)
ansible.builtin.lineinfile:
path: "{{ ansible_user_dir }}/{{ shell_info.rc_file }}"
regexp: "^eval `keychain --eval --agents ssh"
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regular expression is incomplete and missing the closing backtick, which could lead to unexpected matching behavior. Consider using a more complete pattern or escaping special characters properly.

Suggested change
regexp: "^eval `keychain --eval --agents ssh"
regexp: "^eval \\`keychain --eval --agents ssh\\`"

Copilot uses AI. Check for mistakes.
@thaim thaim merged commit 56c9288 into master Jul 27, 2025
2 checks passed
@thaim thaim deleted the ssh-keychain branch July 27, 2025 08:49
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.

1 participant