community.general.ssh_config 模块 – 管理用户的 SSH 配置

注意

此模块是 community.general 集合 (版本 10.1.0) 的一部分。

如果您使用的是 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.general。您需要其他要求才能使用此模块,请参阅 要求 获取详细信息。

要在剧本中使用它,请指定:community.general.ssh_config

community.general 2.0.0 中的新增功能

概要

  • 使用特殊的 IdentityFile 和主机名配置 SSH 主机。

要求

执行此模块的主机需要以下要求。

  • paramiko

参数

参数

注释

add_keys_to_agent

布尔值

community.general 8.2.0 中新增

设置 AddKeysToAgent 选项。

选项

  • false

  • true

controlmaster

字符串

community.general 8.1.0 中新增

设置 ControlMaster 选项。

选项

  • "yes"

  • "no"

  • "ask"

  • "auto"

  • "autoask"

controlpath

字符串

community.general 8.1.0 中新增

设置 ControlPath 选项。

controlpersist

字符串

community.general 8.1.0 中新增

设置 ControlPersist 选项。

dynamicforward

字符串

community.general 10.1.0 中新增

设置 DynamicForward 选项。

forward_agent

布尔值

community.general 4.0.0 中新增

设置 ForwardAgent 选项。

选项

  • false

  • true

group

字符串

此配置文件所属的组。

如果没有给出,则使用 user

host

字符串 / 必需

此配置有效的端点。

可以是互联网上的实际地址,也可以是连接到 hostname 值的别名。

host_key_algorithms

字符串

community.general 6.1.0 中新增

设置 HostKeyAlgorithms 选项。

hostname

字符串

连接到定义的主机时要连接到的实际主机。

identities_only

布尔值

community.general 8.2.0 中新增

指定 SSH 应该只使用配置的认证身份和证书文件(默认文件,或在 ssh_config 文件中明确配置的文件或在 ssh 命令行上传递的文件),即使 ssh-agent 或 PKCS11Provider 或 SecurityKeyProvider 提供更多身份。

选项

  • false

  • true

identity_file

路径

连接到此主机时将使用的身份文件(SSH 私钥)的路径。

文件需要存在并且具有 0600 模式才能有效。

port

字符串

连接到定义的主机时要连接到的实际端口。

proxycommand

字符串

设置 ProxyCommand 选项。

proxyjump 互斥。

proxyjump

字符串

community.general 6.5.0 中新增

设置 ProxyJump 选项。

proxycommand 互斥。

remote_user

字符串

指定要以其身份登录的用户。

ssh_config_file

路径

SSH 配置文件。

如果没有指定 user 和此选项,则使用 /etc/ssh/ssh_config

user 互斥。

state

字符串

主机条目是否存在。

选项

  • "present" ← (默认)

  • "absent"

strict_host_key_checking

字符串

连接到远程主机时是否严格检查主机密钥。

自 community.general 8.6.0 起支持 accept-new 值。

选项

  • "yes"

  • "no"

  • "ask"

  • "accept-new"

user

字符串

此配置文件所属的用户帐户。

如果没有给出并且未指定 ssh_config_file,则使用 /etc/ssh/ssh_config

如果指定了用户,则使用~/.ssh/config

ssh_config_file互斥。

user_known_hosts_file

字符串

设置用户已知主机文件选项。

属性

属性

支持

描述

check_mode

支持:完全支持

可以在check_mode下运行,并在不修改目标的情况下返回更改状态预测。

diff_mode

支持:不支持

在差异模式下,将返回有关已更改内容(或可能需要在check_mode下更改的内容)的详细信息。

示例

- name: Add a host in the configuration
  community.general.ssh_config:
    user: akasurde
    host: "example.com"
    hostname: "github.com"
    identity_file: "/home/akasurde/.ssh/id_rsa"
    port: '2223'
    state: present

- name: Delete a host from the configuration
  community.general.ssh_config:
    ssh_config_file: "{{ ssh_config_test }}"
    host: "example.com"
    state: absent

返回值

常用返回值已在此处记录,以下是此模块特有的字段

描述

hosts_added

列表 / 元素=字符串

已添加主机的列表。

返回:成功

示例:["example.com"]

hosts_change_diff

列表 / 元素=字符串

主机差异更改列表。

返回:发生更改时

示例:[{"example.com": {"new": {"hostname": "github.com", "identityfile": ["/tmp/test_ssh_config/fake_id_rsa"], "port": "2224"}, "old": {"hostname": "github.com", "identityfile": ["/tmp/test_ssh_config/fake_id_rsa"], "port": "2224"}}}]

hosts_changed

列表 / 元素=字符串

已更改主机的列表。

返回:成功

示例:["example.com"]

hosts_removed

列表 / 元素=字符串

已删除主机的列表。

返回:成功

示例:["example.com"]

作者

  • Björn Andersson (@gaqzi)

  • Abhijeet Kasurde (@Akasurde)