How do you use Ansible for security hardening?
IntermediateProductionSecurity and Secrets
Answer
Encode the baseline as a role applied to every host: SSH settings, password policy, kernel sysctls, auditd rules, file permissions, removal of unneeded packages, firewall defaults. Use well-maintained content as a starting point (the DevSec hardening collection, ansible-lockdown CIS roles) and fork the parts you need.
Run it first in --check --diff on stage, and make each control a variable that can be switched off for a documented exception. Verify with an independent scanner (OpenSCAP, Lynis, InSpec), because "the task ran" is not the same as "the host is compliant".
More on Security and Secrets
How do you set up a secure automation user and SSH access?BeginnerHow do you give the automation user sudo with least privilege?IntermediateWhat are the alternatives to Ansible Vault for secrets, and when do you use them?IntermediateHow do you read AWS Secrets Manager and SSM parameters in a playbook?IntermediateHow do you integrate HashiCorp Vault with Ansible?AdvancedHow do you stop secrets from leaking into logs and output?Beginner