AlphaHydrae.ssh-key
Ansible SSH Key
This Ansible role creates an SSH key for a specific user.
If you set ssh_key_root_link to true, it will also create a shortcut (symlink) for the key in the root user's .ssh directory.
Role Variables
SSH Key Settings
ssh_key_user(oruser) - required - The username for which the SSH key will be generated (defaults to the value of theuservariable).ssh_key_bits[integer]- The size of the key in bits (defaults to 8192).ssh_key_comment- A note at the end of the SSH key block (defaults to{{ ssh_key_user }}@{{ ansible_hostname }}, e.g.,jdoe@mycomputer).
SSH Key Location for Non-root Users
ssh_key_dir- The .ssh folder where the key will be created (defaults to{{ host_user_homes }}/{{ ssh_key_user }}/.ssh, wherehost_user_homesis set by the AlphaHydrae.multipass role).ssh_key_file- The path to the SSH key file (defaults to{{ ssh_key_dir }}/id_rsa).
SSH Key Location for the Root User
ssh_key_root_dir- The .ssh folder of the root user (defaults to{{ host_root_home }}/.ssh; thehost_root_homevariable is provided by the AlphaHydrae.multipass role).ssh_key_root_file- The path to the root user's SSH key file (defaults to{{ ssh_key_root_dir }}/id_rsa).
For Creating a Symlink for Root User's Key
ssh_key_root_link[boolean]- Indicates whether to create a symlink for the newly created key in the root user's .ssh folder (defaults tofalse; has no effect ifssh_key_useris the root user).
Dependencies
The AlphaHydrae.multipass role helps find the main directory for user home folders. It sets the following facts with sensible defaults based on the host's system:
host_root_user- Username of the root user (e.g.,root).host_root_group- Group for the root user (e.g.,root).host_root_home- Home directory for the root user (e.g.,/root).host_user_homes- Base directory for user home folders (e.g.,/homeon Linux or/Userson macOS).
Example Playbook
- hosts: servers
roles:
- role: AlphaHydrae.ssh-key
ssh_key_user: jdoe
Custom SSH Key Settings
- hosts: servers
roles:
- role: AlphaHydrae.ssh-key
ssh_key_user: jdoe
ssh_key_bits: 2048
ssh_key_comment: my-key
Using a Default User (e.g., at the playbook level)
- hosts: servers
vars:
user: jdoe
roles:
- role: AlphaHydrae.ssh-key
Creating a Symlink to the Root User's .ssh Directory
- hosts: servers
roles:
- role: AlphaHydrae.ssh-key
ssh_key_user: jdoe
ssh_key_root_link: true
Installa
ansible-galaxy install AlphaHydrae.ssh-keyLicenza
mit
Download
94
Proprietario
