znerol.ssh_kba
角色名称
设置SSH公钥认证,以实现机器之间的通信。
要求
需要安装OpenSSH服务器和客户端软件。
角色变量
在典型的设置中,此角色应用于SSH客户端或SSH服务器。可以通过设置ssh_kba_server_hostname
和ssh_kba_client_hostname
来委派另一方的任务。通常,建议明确指定ssh_kba_server_user
和ssh_kba_client_user
,而不是依赖默认值。
注意:SSH主机密钥是从ansible事实中收集的。因此,确保在所有相关机器上提前收集这些信息是很重要的。
影响服务器的变量
表示公钥认证SSH连接的服务器端点的主机和用户:
ssh_kba_server_hostname: "{{ inventory_hostname }}"
ssh_kba_server_user: # 根据事实确定的服务器上的Ansible用户。
影响客户端的变量
ssh_kba_client_hostname: "{{ inventory_hostname }}"
ssh_kba_client_user: # 根据事实确定的服务器上的Ansible用户。
ssh_kba_client_host_fqdn: # 根据事实确定的服务器的完全限定域名。
ssh_kba_client_host_ip4: # 根据事实确定的服务器的默认IP地址。
ssh_kba_client_host_ip6: # 根据事实确定的服务器的默认IP地址。
影响密钥对的变量
ssh_kba_keypair_type: rsa # 可选值包括dsa、ecdsa、ed25519、rsa
ssh_kba_keypair_size: # 默认省略
ssh_kba_keypair_comment: "{{ ssh_kba_client_user }}@{{ ssh_kba_client_hostname }}"
ssh_kba_keypair_dir: ~/.ssh
ssh_kba_keypair_name: "id_{{ ssh_kba_keypair_type }}"
ssh_kba_keypair_path: "{{ ssh_kba_keypair_dir }}/{{ ssh_kba_keypair_name }}"
ssh_kba_keypair_owner: "{{ ssh_kba_client_user }}"
ssh_kba_keypair_group: # 默认省略
ssh_kba_keypair_attributes: # 默认省略
ssh_kba_keypair_selevel: # 默认省略
ssh_kba_keypair_serole: # 默认省略
ssh_kba_keypair_setype: # 默认省略
ssh_kba_keypair_seuser: # 默认省略
如果ssh_kba_keypair_force
设置为yes
,则将重新生成密钥对。
ssh_kba_keypair_force: # 默认省略
在角色评估期间,将ssh_kba_keypair_pub
设置为密钥对的公钥部分。
影响服务器授权密钥文件的变量
ssh_kba_keypair_pub: # 见上面的密钥对部分
ssh_kba_server_authorized_keys_owner: "{{ ssh_kba_server_user }}"
ssh_kba_server_authorized_keys_comment: # 默认省略
ssh_kba_server_authorized_keys_exclusive: # 默认省略
ssh_kba_server_authorized_keys_key_options: # 默认省略
ssh_kba_server_authorized_keys_manage_dir: # 默认省略
ssh_kba_server_authorized_keys_path: # 默认省略
影响客户端已知主机文件的变量
ssh_kba_client_known_hosts_owner: "{{ ssh_kba_client_user }}"
ssh_kba_client_known_hosts_hash_host | default(omit) }}"
ssh_kba_client_known_hosts_path | default(omit) }}"
为了将服务器的FQDN、IP和主机密钥事实在客户端的known_hosts
中可用,会收集这些信息。覆盖以下任何变量将修改此行为:
ssh_kba_server_host_fqdn: # 根据事实确定的服务器的FQDN。
ssh_kba_server_host_ip4: # 根据事实确定的服务器的默认IP地址。
ssh_kba_server_host_ip6: # 根据事实确定的服务器的默认IP地址。
ssh_kba_server_host_names: # 包含FQDN和默认IP地址的列表。
ssh_kba_server_host_keys: # 包含每对的密钥类型(第一个字段)和实际主机密钥(第二个字段)的列表。默认值为从主机事实中获得的值。
上述变量将用于填充一个包含主机名和密钥对的列表变量:
ssh_kba_server_host_names_and_keys: # 包含主机名(或IP地址)和相应主机密钥(以known_hosts模块接受的形式)的每对列表。
依赖
无。
示例剧本
- hosts: server.example.com
tasks:
- name: 收集客户端事实
delegate: client.example.com
delegate_facts: yes
setup:
- name: >-
针对[email protected]在[email protected]上授予基于密钥的认证
vars:
ssh_kba_server_user: alpha
ssh_kba_client_hostname: client.example.com
ssh_kba_client_user: beta
import_role:
name: znerol.ssh_kba
许可
BSD