ssh-key
Ansible SSH Key
Ansible role that generates an SSH key for a user.
Setting the ssh_key_root_link
to true
will also symlink the key into the root user's .ssh directory.
Role Variables
SSH key properties
ssh_key_user
(oruser
) - required - The user for which to generate an SSH key (defaults to the value of theuser
variable).ssh_key_bits
[integer]
- The number of bits in the generated key (defaults to 8192).ssh_key_comment
- The comment at the end of the SSH key block (defaults to{{ ssh_key_user }}@{{ ansible_hostname }}
, e.g.jdoe@mycomputer
).
Non-root user's SSH key location
ssh_key_dir
- The .ssh directory where the key will be generated (defaults to{{ host_user_homes }}/{{ ssh_key_user }}/.ssh
, wherehost_user_homes
is provided by the AlphaHydrae.multipass role).ssh_key_file
- The location of the SSH key file (defaults to{{ ssh_key_dir }}/id_rsa
).
Root user's SSH key location
ssh_key_root_dir
- The .ssh directory of the root user (defaults to{{ host_root_home }}/.ssh
; thehost_root_home
variable is provided by the AlphaHydrae.multipass role).ssh_key_root_file
- The location of the root user's SSH key file (defaults to{{ ssh_key_root_dir }}/id_rsa
).
Root symlink variables
ssh_key_root_link
[boolean]
- Whether to symlink the generated key into the root user's .ssh directory (defaults tofalse
; has no effect ifssh_key_user
is the root user).
Dependencies
The AlphaHydrae.multipass role is used to determine the base directory where user home directories are located. The role sets the following facts to reasonable defaults depending on the target host's platform:
host_root_user
- The username of the root user (e.g.root
).host_root_group
- The group of the root user (e.g.root
).host_root_home
- The home directory of the root user (e.g./root
).host_user_homes
- The base directory where user home directories are located (e.g./home
on Linux or/Users
on OS X).
Example Playbook
- hosts: servers
roles:
- role: AlphaHydrae.ssh-key
ssh_key_user: jdoe
Custom SSH key properties
- hosts: servers
roles:
- role: AlphaHydrae.ssh-key
ssh_key_user: jdoe
ssh_key_bits: 2048
ssh_key_comment: my-key
With a default user defined (e.g. at the playbook level)
- hosts: servers
vars:
user: jdoe
roles:
- role: AlphaHydrae.ssh-key
Symlink the key into the root user's .ssh directory
- hosts: servers
roles:
- role: AlphaHydrae.ssh-key
ssh_key_user: jdoe
ssh_key_root_link: true
Install
ansible-galaxy install AlphaHydrae/ansible-ssh-key
License
mit
Downloads
68
Owner