Skip to content

Review SSH Configuration Drift With Ansible and Git

Admin
November 20, 2026
5 min read
Intermediate
πŸ’» Target OS: Linux (Ansible controller and OpenSSH hosts)

Before you begin

  • Applies to:Authorized Linux hosts whose SSH configuration is tracked with Ansible and Git.
  • Where to start:Start on the Linux Ansible controller.
  • What you need:Have ansible-core, Git, private repository storage, access to the target hosts, and the approved privilege escalation method.
Guide tools
Guide tools
0/0 Steps (0%)

Downloads

Steps

01

Choose the approved hosts

Save the playbook at the root of a private Git repository. Use the baseline_hosts group and replace the illustrative host with your approved test host.

[baseline_hosts]
linux-lab-01 ansible_host=linux-lab-01.example.com
02

Collect a restricted snapshot

The playbook reads the main sshd_config file, hides raw task output, removes comments, and only saves four directives with bounded values. It writes snapshots on the controller. Check the recap before comparing. A failed host may leave a previous snapshot behind.

Terminal window
ansible-playbook -i inventory.ini ssh_config_baseline.yml
03

Record the reviewed baseline

Check that every intended host produced a snapshot and that the content matches the intended allowlist. After review, selectively stage the approved files and commit them. Restrict access to the Git history.

04

Compare the next capture

Rerun the playbook and compare Git status and diff. An approved MaxAuthTries change might be expected. An unplanned PasswordAuthentication change merits investigation. Track new and retired hosts separately from content changes.

Terminal window
git status --short -- snapshots/
git diff -- snapshots/
05

Verify effective behavior before closing

Verify

Have the service owner compare the result with the change record. Review includes and Match blocks separately, and use the approved sshd -T procedure for the intended connection context. Commit the new baseline after review.

References

Comments