How yel-hadr/cloud-1_42 works
Purpose and Entry Point
This repository provisions and hardens a single AWS EC2 host for the 42 cloud-1 project. The primary execution entry point is site.yml, run against the host/group defined in inventory.yaml. Ansible connection, vault, and execution defaults are centralized in ansible.cfg.
Deployment Control Plane
Ansible is the runtime and orchestration boundary: the operator runs playbooks locally and applies state remotely over SSH as the ubuntu user, escalating privileged tasks with become. The target inventory boundary is inventory.yaml; external infrastructure is an AWS EC2 instance. Required Ansible dependencies are declared in requirements.yml.
Ordered Provisioning Pipeline
The top-level play applies two major stages in sequence:
1. Baseline operating-system setup through roles/common/tasks/main.yml.
2. Host security hardening through roles/security/tasks/main.yml.
This ordering matters: the common role establishes machine identity and administrative prerequisites before security policy constrains access.
Common Baseline Role
roles/common/ defines the reusable base-host layer: package installation, timezone and hostname configuration, and admin-user setup. Its desired-state inputs are in roles/common/defaults/main.yml; execution is in roles/common/tasks/main.yml; service reactions are isolated in roles/common/handlers/main.yml. This role is the boundary between a stock Ubuntu EC2 image and a standardized managed host.
Security Hardening Role
roles/security/ owns network access, SSH posture, intrusion protection, and automatic patching. The main orchestration is roles/security/tasks/main.yml, with configurable defaults in roles/security/defaults/main.yml and reload/restart behavior in roles/security/handlers/main.yml.
Its key rendered-policy boundary is template-based configuration:
• roles/security/templates/99-hardening.conf.j2 for SSH daemon hardening.
• roles/security/templates/jail.local.j2 for Fail2ban policy.
SSH configuration is validated before installation, and SSH is reloaded rather than restarted to preserve active sessions. Firewall sequencing allows OpenSSH before UFW is enabled, preventing a provisioning-induced lockout.
Secrets and Idempotency Boundaries
Sensitive values are stored encrypted in vault.yml and consumed through Ansible Vault; the vault password file is intentionally external to version control. The playbook is designed as declarative desired state: repeated execution should converge without changes. Handlers provide the control-flow boundary between configuration changes and deferred service reloads, avoiding unnecessary runtime disruption.
Main entry points: site.yml Provisioning playbook · tasks/main.yml Hardening orchestration · tasks/main.yml Baseline setup · handlers/main.yml Security handlers
Components 15
Deployment Control
Local Ansible execution applies desired state to one EC2 host.
- Operator
- Ansible defaults · Connection, vault, and execution defaults.
ansible.cfg - Ansible dependencies
requirements.yml - Target inventory
inventory.yaml - Encrypted secrets · Vault password file remains external to version control.
vault.yml - Provisioning playbook · Runs common first, then security.
site.yml
Common Baseline
Standardizes the stock Ubuntu host before security policy.
- Baseline inputs
roles/common/defaults/main.yml - Baseline setup · Packages, timezone, hostname, and admin-user setup.
roles/common/tasks/main.yml - Baseline handlers
roles/common/handlers/main.yml
Security Hardening
Controls SSH, firewall, intrusion protection, and patching.
- Hardening inputs
roles/security/defaults/main.yml - Hardening orchestration · Applies firewall, SSH, Fail2ban, and automatic patching.
roles/security/tasks/main.yml - SSH hardening policy · Validated before installation; SSH is reloaded.
roles/security/templates/99-hardening.conf.j2 - Fail2ban policy
roles/security/templates/jail.local.j2 - Security handlers · Defers reloads and restarts until configuration changes.
roles/security/handlers/main.yml
Other components
- AWS EC2 host · Managed remotely over SSH as ubuntu with privilege escalation.
Connections 18
- Operator → Provisioning playbook: runs
- Ansible defaults → Provisioning playbook: configures execution
- Ansible dependencies → Provisioning playbook: provides dependencies
- Target inventory → Provisioning playbook: selects host
- Encrypted secrets → Provisioning playbook: supplies secrets
- Provisioning playbook → Baseline setup: stage 1
- Provisioning playbook → Hardening orchestration: stage 2
- Provisioning playbook → AWS EC2 host: applies over SSH
- Baseline inputs → Baseline setup: desired-state inputs
- Baseline setup → Baseline handlers: notifies on change
- Baseline setup → AWS EC2 host: standardizes host
- Baseline setup → Hardening orchestration: administrative prerequisite
- Hardening inputs → Hardening orchestration: desired-state inputs
- SSH hardening policy → Hardening orchestration: renders SSH policy
- Fail2ban policy → Hardening orchestration: renders jail policy
- Hardening orchestration → Security handlers: notifies on change
- Hardening orchestration → AWS EC2 host: hardens host
- Security handlers → AWS EC2 host: reloads services