community.general.ssh_config (8.5.0) — module

Manage SSH config for user

| "added in version" 2.0.0 of community.general"

Authors: Björn Andersson (@gaqzi), Abhijeet Kasurde (@Akasurde)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Configures SSH hosts with special C(IdentityFile)s and hostnames.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Delete a host from the configuration
  community.general.ssh_config:
    ssh_config_file: "{{ ssh_config_test }}"
    host: "example.com"
    state: absent

Inputs

    
host:
    description:
    - The endpoint this configuration is valid for.
    - Can be an actual address on the internet or an alias that will connect to the value
      of O(hostname).
    required: true
    type: str

port:
    description:
    - The actual port to connect to when connecting to the host defined.
    type: str

user:
    description:
    - Which user account this configuration file belongs to.
    - If none given and O(ssh_config_file) is not specified, C(/etc/ssh/ssh_config) is
      used.
    - If a user is given, C(~/.ssh/config) is used.
    - Mutually exclusive with O(ssh_config_file).
    type: str

group:
    description:
    - Which group this configuration file belongs to.
    - If none given, O(user) is used.
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description:
    - Whether a host entry should exist or not.
    type: str

hostname:
    description:
    - The actual host to connect to when connecting to the host defined.
    type: str

proxyjump:
    description:
    - Sets the C(ProxyJump) option.
    - Mutually exclusive with O(proxycommand).
    type: str
    version_added: 6.5.0
    version_added_collection: community.general

controlpath:
    description:
    - Sets the C(ControlPath) option.
    type: str
    version_added: 8.1.0
    version_added_collection: community.general

remote_user:
    description:
    - Specifies the user to log in as.
    type: str

proxycommand:
    description:
    - Sets the C(ProxyCommand) option.
    - Mutually exclusive with O(proxyjump).
    type: str

controlmaster:
    choices:
    - 'yes'
    - 'no'
    - ask
    - auto
    - autoask
    description:
    - Sets the C(ControlMaster) option.
    type: str
    version_added: 8.1.0
    version_added_collection: community.general

forward_agent:
    description:
    - Sets the C(ForwardAgent) option.
    type: bool
    version_added: 4.0.0
    version_added_collection: community.general

identity_file:
    description:
    - The path to an identity file (SSH private key) that will be used when connecting
      to this host.
    - File need to exist and have mode V(0600) to be valid.
    type: path

controlpersist:
    description:
    - Sets the C(ControlPersist) option.
    type: str
    version_added: 8.1.0
    version_added_collection: community.general

identities_only:
    description:
    - Specifies that SSH should only use the configured authentication identity and certificate
      files (either the default files, or those explicitly configured in the C(ssh_config)
      files or passed on the ssh command-line), even if ssh-agent or a PKCS11Provider
      or SecurityKeyProvider offers more identities.
    type: bool
    version_added: 8.2.0
    version_added_collection: community.general

ssh_config_file:
    description:
    - SSH config file.
    - If O(user) and this option are not specified, C(/etc/ssh/ssh_config) is used.
    - Mutually exclusive with O(user).
    type: path

add_keys_to_agent:
    description:
    - Sets the C(AddKeysToAgent) option.
    type: bool
    version_added: 8.2.0
    version_added_collection: community.general

host_key_algorithms:
    description:
    - Sets the C(HostKeyAlgorithms) option.
    type: str
    version_added: 6.1.0
    version_added_collection: community.general

user_known_hosts_file:
    description:
    - Sets the user known hosts file option.
    type: str

strict_host_key_checking:
    choices:
    - 'yes'
    - 'no'
    - ask
    description:
    - Whether to strictly check the host key when doing connections to the remote host.
    type: str

Outputs

hosts_added:
  description: A list of host added.
  returned: success
  sample:
  - example.com
  type: list
hosts_change_diff:
  description: A list of host diff changes.
  returned: on change
  sample:
  - 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'
  type: list
hosts_changed:
  description: A list of host changed.
  returned: success
  sample:
  - example.com
  type: list
hosts_removed:
  description: A list of host removed.
  returned: success
  sample:
  - example.com
  type: list