LOGBOOK

HELP

Quiz Entry - updated: 2026.11.12

What does a template for /etc/ssh/sshd_config built from variables and facts look like, and what makes it per-host?

The file is written out in full; only the values that differ are placeholders, such as Port {{ ssh_port }}, ListenAddress {{ ansible_facts['default_ipv4']['address'] }} and PermitRootLogin {{ root_allowed }}.

# {{ ansible_managed }}
# DO NOT MAKE LOCAL MODIFICATIONS TO THIS FILE BECAUSE THEY WILL BE LOST

Port {{ ssh_port }}
ListenAddress {{ ansible_facts['default_ipv4']['address'] }}

HostKey /etc/ssh/ssh_host_ed25519_key
SyslogFacility AUTHPRIV

PermitRootLogin {{ root_allowed }}
AllowGroups {{ groups_allowed }}
PasswordAuthentication {{ passwords_allowed }}
UsePAM yes
Subsystem sftp /usr/libexec/openssh/sftp-server

Two sources fill it in:

  • Variables set by the playbook author: ssh_port, root_allowed, groups_allowed, passwords_allowed. Change them once, and every host's file follows.
  • Facts discovered on each host: default_ipv4.address differs per host, so each SSH daemon listens on its own address without anyone typing it in.

The header line marks the file as managed (see the ansible_managed card). For a file like this, add validate: /usr/sbin/sshd -t -f %s to the template task: a broken sshd_config can lock you out of the host you are configuring over SSH.

Go deeper:

From Quiz: ITIA / Ansible: Managing Files and Jinja2 Templates | Updated: Nov 12, 2026