Review SSH Configuration Drift With Ansible and Git
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
Downloads
Steps
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.comCollect 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.
ansible-playbook -i inventory.ini ssh_config_baseline.ymlRecord 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.
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.
git status --short -- snapshots/git diff -- snapshots/Verify effective behavior before closing
VerifyHave 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
Your feedback keeps these production procedures accurate and battle-tested.