Skip to content

The Ansible Configuration system in Squirrel Servers Manager (SSM) provides a robust mechanism for managing Ansible configuration settings. It allows users to view, create, update, and delete configuration entries through a RESTful API. The system ensures that configuration changes are persistent, secure, and properly validated.

In a Nutshell (🌰)

  • SSM provides a complete Ansible configuration management system
  • Configuration is stored in standard INI format in ansible.cfg
  • RESTful API for reading and modifying configuration options
  • Security measures prevent prototype pollution and file system attacks
  • Detailed documentation for all configuration options with descriptions

Configuration Architecture

SSM implements the Ansible configuration system using a Clean Architecture approach with the following components:

Ansible Configuration Architecture
Ansible Configuration Architecture
Figure 1: Ansible Configuration System

Key Components

  1. Ansible Config Module

    • Controller: Provides REST API endpoints for configuration management
    • Service: Contains the business logic for reading and writing configuration
    • File System Access: Handles the actual reading and writing of the config file
  2. Configuration Storage

    • Stored in standard INI format in ansible.cfg
    • Located in the SSM data directory (e.g., .data.prod/config)
    • Initial configuration copied from template if not present
  3. Integration with Ansible Module

    • The Ansible module uses the configuration during command execution
    • Configuration path is injected into the environment variable (ANSIBLE_CONFIG) when running commands

Configuration File Format

The Ansible configuration file (ansible.cfg) follows the standard INI format with sections and key-value pairs:

ini
[section_name]
# Description of the configuration option
key_name=value

# Description of a deactivated option
;deactivated_key=value

The SSM Ansible Configuration system supports:

  • Multiple sections: Organize related settings
  • Active/Deactivated entries: Comment out options with a semicolon (;)
  • Descriptions: Document the purpose and valid values for each option (used by SSM's API/UI)

Configuration API

SSM provides a REST API for managing Ansible configuration programmatically.

(Note: Base path /api/ precedes these routes)

Get Configuration

http
GET /api/ansible-config

Returns the complete Ansible configuration as a JSON object, including descriptions and activation status:

json
{
  "defaults": {
    "host_key_checking": {
      "value": "False",
      "deactivated": false,
      "description": "Whether to verify host keys"
    },
    // ... other entries
  },
  "privilege_escalation": {
    "become": {
      "value": "False",
      "deactivated": false,
      "description": "Toggles the use of privilege escalation"
    }
    // ... other entries
  }
}

Create Configuration Entry

http
POST /api/ansible-config

Request body:

json
{
  "section": "defaults",
  "key": "new_option",
  "value": "some_value",
  "deactivated": false,
  "description": "Description for the new option"
}

Update Configuration Entry

http
PUT /api/ansible-config

Request body (identifies entry by section and key):

json
{
  "section": "defaults",
  "key": "host_key_checking",
  "value": "True", // New value
  "deactivated": false,
  "description": "Updated description"
}

Delete Configuration Entry

http
DELETE /api/ansible-config

Request body (identifies entry by section and key):

json
{
  "section": "defaults",
  "key": "host_key_checking"
}

Common Configuration Options

SSM's Ansible configuration includes many standard Ansible options. Here are some common ones you might interact with:

[defaults] Section

OptionDescriptionDefaultRecommended Value/Note
host_key_checkingControls SSH host key verificationTrueFalse often used in non-interactive/dev environments, but less secure.
inventoryPath to inventory files/etc/ansible/hostsSSM manages inventory dynamically; this default is usually ignored.
timeoutConnection timeout in seconds10Increase (e.g., 30) for slow networks or long-running connections.
remote_userDefault user for SSH connectionsCurrent userUsually overridden by device-specific settings in SSM.
interpreter_pythonPath to Python on target hostsautoauto is generally best for auto-detection.
forksMaximum parallel processes5Increase for faster execution on multiple hosts, resource permitting.
pipeliningReduces SSH operations for performanceFalseTrue can significantly speed up playbooks but requires requiretty disabled in sudoers on targets.

[privilege_escalation] Section

OptionDescriptionDefaultRecommended Value/Note
becomeEnable privilege escalation globallyFalseUsually managed per-device or per-play in SSM, but can set a default.
become_methodMethod for escalation (sudo, su, etc.)sudosudo is most common.
become_userTarget user for escalationrootTypically root.
become_ask_passPrompt for privilege passwordFalseShould remain False as SSM handles passwords via vault.

[ssh_connection] Section

OptionDescriptionDefaultRecommended Value/Note
ssh_argsAdditional arguments for the ssh command-C -o ControlMaster=auto -o ControlPersist=60sDefault enables compression and connection sharing. Modify with caution.
control_path_dirDirectory for SSH control path sockets~/.ansible/cpDefault is usually fine.
pipeliningSame as pipelining in [defaults]Value from [defaults]Set True here or in [defaults] for performance.

For a full list, see the official Ansible Configuration Settings documentation.

Security Considerations

The SSM Ansible Configuration system includes safeguards:

  • Prototype Pollution Prevention: Rejects section/key names like __proto__.
  • Safe File Operations: Ensures edits only occur within the expected ansible.cfg file path.
  • Input Validation: API endpoints validate incoming data structure and types.
  • Error Handling: Provides informative errors without exposing excessive system detail.

Integration with Ansible Execution

SSM ensures Ansible uses the managed ansible.cfg by:

  1. Setting Environment Variable: Sets the ANSIBLE_CONFIG environment variable to point to the specific ansible.cfg file path before running ansible-runner.
  2. Providing Defaults: Ships with a sensible default ansible.cfg to ensure consistent operation.

This allows users to customize global Ansible behavior within the SSM context.

Next step

🔌
Ansible Connection Methods

Learn about SSH connection methods used by Ansible.

Made with love