prepare-host.yaml

Overview

The prepare-host.yaml file is an automation playbook that configures system resource limits and Docker service settings on a host machine. Its primary purpose is to adjust kernel and user-level limits to optimize system performance and stability, particularly for applications that require high file descriptor counts, memory lock capabilities, and process limits. It also configures Docker daemon resource restrictions to support these enhanced limits and ensures that changes take effect by restarting the Docker service if necessary.

This playbook utilizes system configuration files such as /etc/security/limits.conf and /etc/sysctl.conf, and modifies systemd service unit files for Docker. It is structured as a sequence of tasks, each performing a specific configuration step.

Tasks and Their Functionalities


1. Adjust Limits

Purpose:
Modify /etc/security/limits.conf to set hard and soft limits for file descriptors (nofile), memory locking (memlock), and number of processes (nproc) to high or unlimited values.

Implementation Details:

Parameters:

Example Usage:
No direct invocation parameters; this task runs as part of the playbook.


2. Sysctl Limits

Purpose:
Set the kernel parameter vm.max_map_count to 512000 in /etc/sysctl.conf, which controls the maximum number of memory map areas a process may have. This is critical for applications like Elasticsearch that require large numbers of memory mappings.

Implementation Details:

Parameters:


3. Docker Memlock Limit

Purpose:
Modify the Docker systemd service file to set the LimitMEMLOCK parameter to infinity, allowing Docker containers to lock unlimited amounts of memory, which is necessary for some high-performance or security-sensitive workloads.

Implementation Details:

Parameters:


4. Restart Docker

Purpose:
Restart the Docker service to apply changes made to its systemd service configuration.

Implementation Details:

Parameters:


Implementation Details and Algorithms

Interaction with Other System Components

Visual Diagram

flowchart TD
A[Start prepare-host.yaml] --> B[Adjust /etc/security/limits.conf]
B --> C[Set vm.max_map_count in /etc/sysctl.conf]
C --> D[Modify Docker systemd service: LimitMEMLOCK=infinity]
D --> E{Docker config changed?}
E -- Yes --> F[Restart Docker service]
E -- No --> G[End]
F --> G[End]

This flowchart illustrates the sequential execution of tasks and the conditional restart of the Docker service based on configuration changes.