Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Server barebones

A single Ansible playbook for preparing a new Debian or Ubuntu server. Edit the configuration block at the top of server-barebones.yml, then run one command:

ansible-playbook server-barebones.yml

The playbook creates its inventory from server_ip. You do not need an inventory file or command-line variables. It probes the hardened administrator connection first, then falls back to the provider bootstrap connection. This lets the same command resume after an interrupted SSH transition.

Before running

Provision the server with one of ssh_public_keys installed for the provider's initial account. That account must be root or have passwordless sudo.

Set every CHANGE_ME value. ssh_allowed_cidrs: [] permits key-only SSH from any address, which works for changing networks and dynamic public addresses. If you have a stable address, add it to restrict SSH. A single IPv4 address uses /32; a single IPv6 address uses /128.

Leave initial_ssh_private_key_file empty when ssh-agent or a normal key under ~/.ssh can make the initial connection. Otherwise, provide an absolute path.

Choose what happens to the provider account:

  • retain_initial_user: true keeps it and permits SSH on the hardened port.
  • retain_initial_user: false removes a non-root provider account and its home after the full baseline passes. Existing login sessions and processes receive a clean termination request before account removal.
  • The root account is never deleted, but root SSH is always disabled.

Do not commit your edited IP address, usernames, or public keys unless you mean to publish them.

What it configures

  • A non-root administrator with key-only SSH and passwordless sudo
  • A configurable SSH port, optional source CIDR allow-list, and automatic removal of the old port after reconnection succeeds
  • UFW with default-deny inbound policy and only SSH, HTTP, and HTTPS admitted
  • fail2ban, unattended upgrades, AppArmor, auditd, rsyslog, persistent journald, disabled core dumps, and kernel hardening
  • A C.UTF-8 server locale without importing unsupported client locale values
  • Docker with direct public access to published container ports blocked
  • Nginx on ports 80 and 443, returning 404 until another playbook replaces its default configuration
  • A local placeholder TLS certificate for the blank HTTPS server

Future project playbooks own application firewall rules, domains, certificates, containers, and Nginx sites. This playbook does not reset UFW, so those rules survive later baseline runs.

Limits

This supports Debian and Ubuntu servers using systemd. It does not secure the gap between server creation and the first Ansible connection. Use the provider firewall during provisioning when one is available.

With an empty ssh_allowed_cidrs list, the SSH port is public. Authentication still requires a configured private key, and password and root login remain disabled. That mode is not suitable when your policy requires network-level SSH restriction.

The placeholder certificate is self-signed. Browsers will reject it, which is expected. A project playbook should replace it with the real certificate and site configuration.

Validation

Run the same check used by CI:

ansible-playbook --syntax-check server-barebones.yml

The untouched template also refuses to continue while any required CHANGE_ME value remains.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors