Automating server hardening with Ansible and CIS benchmarks

Server hardening often turns into a folder of one-off notes: SSH settings changed on one host, audit logging enabled on another, and a checklist buried in a ticket. Automating server hardening with Ansible and CIS benchmarks turns those scattered actions into a repeatable control system, giving infrastructure teams a clear record of what is configured and why.

A CIS benchmark is not a universal configuration. Controls vary by operating system, distribution, service role and benchmark version, while Level 2 profiles can interrupt workloads that work perfectly well under Level 1. Ansible is valuable here because the same playbooks can collect evidence, report gaps and, after approval, enforce the approved state.

The practical approach is to begin with read-only checks, turn the findings into small role-specific policies, and preserve exceptions as explicit code rather than undocumented manual changes. That creates useful automation without pretending every control fits every server.

Establish a measurable hardening baseline

Choose the benchmark edition and operating-system scope first, then map each relevant control to an internal owner. A Linux baseline might cover SSH authentication, file permissions, password policies, firewall rules, auditd or journald, time synchronisation and unnecessary services. Record the source and version beside the code so an auditor can trace each setting to its policy.

Treat baseline selection as a risk decision rather than a purity test. Split controls into preventive, detective and operational groups, and record why a control is not applicable to a particular role. That record is often more valuable than an unexplained deviation because it gives reviewers evidence and gives automation a stable input.

Model controls around server roles

Create separate roles or playbooks for web, database, application, build and general-purpose hosts. A database should not inherit the same service and kernel profile as a jump host, and ephemeral cloud instances need different filesystem and package rules from long-lived servers. Role-specific profiles also make rollbacks and change approvals much easier to explain.

Keep shared controls in one common role and variable file, then layer role-specific deviations over them. For example, all servers might require central time synchronisation and SSH key authentication, while only internet-facing systems receive a stricter firewall or intrusion-detection configuration. This avoids duplicated playbooks without hiding important differences.

Encode controls as versioned Ansible content

Store the hardening policy in Git beside the inventory, secrets handling and deployment playbooks. Use clearly named variables for ports, accounts and approved exceptions, but keep actual secrets out of Git. Review changes through the same pull-request process as application code, and tag releases so an incident responder can identify the control version applied to a host.

Build tasks from supported Ansible modules and validate them with ansible-playbook --check --diff before changing the target. Package installation, sysctl values, service state and file modes are usually straightforward; audit rules and SSH settings deserve additional care because a bad rule can overload the server or lock out administration. Reboot-required changes should use handlers and an explicit maintenance process rather than happening silently.

Keep the mapping between CIS sections and tasks close to the implementation. A small machine-readable index of control identifiers, task names and evidence commands lets reports show coverage without duplicating the entire benchmark. It also reveals when a module upgrade changes behaviour, a common source of otherwise mysterious configuration drift.

Test before enforcing changes

Start with an audit-only run against a representative host. Ansible’s check mode exposes many pending changes, but it does not simulate every package, kernel or service effect. Validate results in a lab with the same operating system and application stack, then run the real playbook against one low-risk server with console access available.

Execution should be staged, serial and observable. Test SSH and firewall changes first, monitor the host for failed logins and service health, and use a narrow blast radius. Karl’s virtualisation testing workstation illustrates the value of isolated hardware for exercising these combinations before they reach production; the same discipline applies when a local virtualisation host is easier to snapshot than a live appliance.

Fit automation to Australian operations

Australian geography makes placement part of hardening operations. Sydney and Melbourne are major cloud regions and common locations for enterprise infrastructure, while Brisbane and Perth users may see additional latency when workloads are placed far from their teams or customers. Ansible can run from a secured management runner in either city, but controllers should use regional endpoints, resilient connectivity and tested failover rather than depend on a single office network.

Hybrid work and BYOD habits also change the threat model. Staff connect from home connections on NBN plans and from personal tablets or phones, often through VPN or zero-trust access services. Hardening the estate is therefore not enough; identity, endpoint management, conditional access and timely patching still matter. Australian businesses also rely on a mix of internal teams, managed service providers and independent consultants. My independent IT consultancy supports infrastructure planning, cloud migration and systems architecture, reflecting the need for automation that clients can maintain rather than an obscure platform imposed upon them.

Australian legal and regulatory context adds another reason to keep good evidence. The Privacy Act 1988 and the Australian Privacy Principles can make server configuration relevant to personal information, while the Notifiable Data Breaches scheme requires organisations to assess eligible incidents. CIS controls support logging, access restriction and resilience, but they are not a substitute for privacy governance or the ACSC’s Essential Eight. Map automated controls to those obligations without claiming that benchmark compliance alone satisfies the law.

Monitor drift and manage exceptions

Compliance is a point-in-time result, so schedule recurring audit-mode runs and compare them with the last enforced state. Feed failed controls into the normal monitoring channel rather than creating an alert nobody owns. Metrics such as affected hosts, control failure rates and mean time to remediate make it easier to justify maintenance work and distinguish a widespread change from a single misconfigured machine.

Treat every exception as an Ansible variable with an owner, reason, review date and compensating control where appropriate. Expiring exceptions should fail the next policy check instead of becoming permanent. Store execution logs and control reports as operational evidence, with retention aligned to the Australian organisation’s privacy, security and contractual requirements.

Recommended path to production hardening

A dependable first cycle is small, measured and reversible. It produces a baseline report, a reviewed set of changes and a repeatable way to prove the result. The automation should make the safest state the easiest state to maintain.

  • Pin one CIS benchmark version for each supported operating system and record its source.
  • Define shared controls and role-specific exceptions in version-controlled Ansible variables.
  • Run audit-only checks continuously and publish control failures to the operations dashboard.
  • Exercise changes in a disposable test environment before every enforcement release.
  • Roll out to a small server group with serial execution, health checks and console access.
  • Review exceptions, control drift and business impact after each production run.

Choose a non-critical system, capture its current configuration, and have both operations and security owners review the proposed changes. Decide in advance what constitutes a failed deployment and how the team will restore access.

Run the audit-only playbook against one representative Australian server this week, assign an owner to every exception, and schedule the first reviewed enforcement run with your change lead.

Experience

Information Technology Consulting

Independent Practice

Provides IT consulting services focused on infrastructure planning, cloud migration strategy, and systems architecture. Engagements draw on years of hands-on sysadmin and development experience across Linux, Windows, and hybrid environments.

K9 Search & Rescue Volunteer

Ongoing

Active participant in K9 Search & Rescue operations, combining technical logistics skills with field support for canine search teams.

Karl Katzke's Blog

October 2006 – May 2014

Published a long-running personal technology blog covering cloud vs. in-house infrastructure, F# and Mono on OSX, hardware vendor critiques, RAID card performance analysis, and sysadmin storytelling. Notable posts include "When Sysadmins Ruled the Earth" (May 15, 2014) and "Getting Started with F# and Mono on OSX" (December 22, 2012).

Credentials

A small badge icon with a shield shape in muted blue tones on a light background

Systems Administration

Deep experience with Linux (RHEL, SLES, CentOS), high-availability clusters, and STONITH configurations.

A small badge icon with a gear shape in muted blue tones on a light background

Cloud Infrastructure

Practical knowledge of AWS EC2, reserved instances, and cost analysis for cloud vs. on-premises deployments.

A small badge icon with a code symbol in muted blue tones on a light background

Development

Proficient in F#, PHP (Symfony), and cross-platform tooling including Mono and MonoDevelop on OSX.

Studies

F# & Functional Programming

Self-directed, 2012

Explored strongly typed functional programming with F# on OSX using the Mono runtime. Published a detailed getting-started guide covering toolchain setup and cross-platform game development research.

High-Availability & Cluster Management

Professional Development, 2009

Configured and documented crm_mon email alerting for STONITH events on SLES11-HAE clusters, integrating with Nagios monitoring for production environments.

Hardware & Storage Performance

Ongoing

Conducted hands-on benchmarking of SATA/SAS RAID controllers including HighPoint RocketRaid 2740 and LSI/SuperMicro AOC-USASLP2-H8iR, comparing against software RAID configurations.

Skills

A small icon representing a server with clean geometric lines in slate blue

Linux Administration

RHEL, SLES, CentOS — package management, kernel tuning, HA clustering, and monitoring integration.

A small icon representing a cloud shape with clean geometric lines in slate blue

Cloud Architecture

AWS EC2, reserved-instance planning, cost modeling, and hybrid infrastructure strategy.

A small icon representing code brackets with clean geometric lines in slate blue

F# & .NET/Mono

Functional programming on OSX, MonoDevelop toolchain, and cross-platform game-dev exploration.

A small icon representing a database cylinder with clean geometric lines in slate blue

PHP & Symfony

Web application development with the Symfony framework and the broader PHP ecosystem.

A small icon representing a storage drive with clean geometric lines in slate blue

Storage & RAID

SATA/SAS controller evaluation, md RAID configuration, and performance benchmarking.

A small icon representing a shield with clean geometric lines in slate blue

High Availability

Pacemaker, STONITH, crm_mon alerting, and Nagios integration for production cluster monitoring.