Deploy with Ansible

This guide provides a complete Ansible role for installing and enrolling LinuxGuard. Credentials are encrypted with Ansible Vault so no secrets appear in plaintext in your repository. The role is idempotent — safe to run repeatedly against already-enrolled servers.

Prerequisites

  • Ansible 2.9+ or ansible-core 2.12+ installed on the control node

  • Target hosts reachable via SSH with sudo access

  • A LinuxGuard API key and tenant ID (from the LinuxGuard console)

Role Structure

The role follows the standard Ansible role directory layout. Create this structure under your roles/ directory, or generate the skeleton with ansible-galaxy role init linuxguard:

roles/
└── linuxguard/
    ├── defaults/
    │   └── main.yml       # Default variable values (lowest precedence)
    ├── handlers/
    │   └── main.yml       # Handler: restart agent service
    ├── meta/
    │   └── main.yml       # Role metadata (galaxy_info, dependencies)
    └── tasks/
        └── main.yml       # Core task list

Encrypting Secrets with Ansible Vault

Use ansible-vault encrypt_string to encrypt individual values. This approach encrypts the value while keeping the variable name visible in version control, making it easy to audit which variables are vault-protected.

Run these commands on your control node and paste the output into defaults/main.yml:

Each command prompts for a vault password and prints an encrypted block. Copy the full output (including the !vault | line) into your defaults file as shown in the next section.

Role Files

defaults/main.yml

tasks/main.yml

Note: The args: creates: /var/lib/linuxguard/config guard on the enroll task skips enrollment if the agent is already enrolled. See Automated Deployment Overview for details on the agent's built-in idempotency behavior.

handlers/main.yml

meta/main.yml

Running the Role

Create a site.yml playbook at the root of your project to apply the role to your inventory:

Run the playbook and supply the vault password:

Note: If you use AWX or Ansible Tower, store the vault password as a Credential object. The --ask-vault-pass flag is not needed — AWX injects the vault password automatically.

Inline Playbook (Alternative)

If you prefer a single-file playbook without a role structure, the equivalent inline form requires no directory layout:

Run the same way: ansible-playbook site.yml --ask-vault-pass.

Verifying the Deployment

Add a verification task at the end of tasks/main.yml to confirm the agent is running after each playbook run:

This task fails the play immediately if the service is not active, surfacing installation or enrollment errors before the run is marked successful. Enrolled servers also appear in the LinuxGuard console under Infrastructure within a few minutes of enrollment.


Related: Automated Deployment Overview | Installation | Configuration

Last updated

Was this helpful?