Centreon CLAPI Restore
This role restores Centreon monitoring configuration from a CLAPI (Command Line API) backup file.
Centreon CLAPI Restore Role
Overview
This role restores Centreon monitoring configuration from a CLAPI (Command Line API) backup file. It automatically identifies the latest backup, imports the configuration, and applies it to the Centreon server. This role is the companion to centreon_clapi_backup.
Purpose
- Disaster Recovery: Restore complete Centreon configuration after system failure
- Configuration Rollback: Revert to a previous configuration snapshot
- System Migration: Transfer Centreon configuration to a new server
- Testing: Create test environments from production backups
- Automated Recovery: Streamline the restoration process
Requirements
- Ansible 2.9 or higher
- Centreon installed with CLAPI available (
centreoncommand) - Admin credentials for Centreon stored in Ansible Vault
- CLAPI backup files created by
centreon_clapi_backuprole - Target host must have the
centreonCLI tool in PATH
Role Variables
Required Variables
| Variable | Required | Description |
|---|---|---|
vault_centreon_admin_password | Yes | Centreon admin password (stored in Ansible Vault) |
Optional Variables
| Variable | Default | Description |
|---|---|---|
centreon_clapi_restore_backup_path | /media/nas_win_share/centreon/clapi | Directory containing CLAPI backup files |
centreon_clapi_restore_admin_user | admin | Centreon admin username for CLAPI operations |
Variable Details
vault_centreon_admin_password
The password for the Centreon admin user. This must be stored in an Ansible Vault file.
Example vault variable:
vault_centreon_admin_password: "YourSecurePassword123"
centreon_clapi_restore_backup_path
Directory where CLAPI backup files are stored. The role will search for files matching the pattern centreon_clapi_backup_*.txt.
Example:
centreon_clapi_restore_backup_path: /mnt/backup/centreon/clapi
centreon_clapi_restore_admin_user
The Centreon admin username. Default is admin but can be changed if you use a different admin account.
Example:
centreon_clapi_restore_admin_user: monitoring_admin
Dependencies
This role has no dependencies on other Ansible roles, but requires:
- CLAPI backup files created by
centreon_clapi_backuprole - NAS mount configured if restoring from network storage
- Centreon server with CLAPI functionality
Example Playbook
Basic Usage (Restore Latest Backup)
---
- name: Restore Centreon Configuration
hosts: centreon
become: true
roles:
- centreon_clapi_restore
Restore from Custom Backup Location
---
- name: Restore Centreon from Custom Location
hosts: centreon
become: true
vars:
centreon_clapi_restore_backup_path: /mnt/backup2/centreon
roles:
- centreon_clapi_restore
Restore with Custom Admin User
---
- name: Restore Centreon with Custom Admin
hosts: centreon
become: true
vars:
centreon_clapi_restore_admin_user: monitoring_admin
roles:
- centreon_clapi_restore
What This Role Does
- Finds all CLAPI backup files in the specified backup directory
- Identifies the latest backup based on file modification time
- Fails gracefully if no backup files are found
- Displays the backup being restored for user confirmation
- Imports the configuration using
centreon -icommand - Applies the configuration using
APPLYCFGto poller 1 - Confirms successful restoration with debug output
Restoration Process Details
Step 1: Import Configuration
centreon -u admin -p 'password' -i /path/to/backup.txt
This command imports all objects from the backup file:
- Hosts and host templates
- Services and service templates
- Commands, time periods, contacts
- All other Centreon configuration objects
Step 2: Apply Configuration
centreon -u admin -p 'password' -a APPLYCFG -v 1
This command:
- Generates new configuration files
- Validates the configuration
- Deploys to poller 1 (Central)
- Reloads monitoring engine
Backup File Selection
The role automatically selects the most recent backup using these criteria:
- Searches for files matching pattern:
centreon_clapi_backup_*.txt - Sorts by modification time (mtime)
- Uses the newest file
Example backup files (newest first):
centreon_clapi_backup_20260107_190530.txt <- This will be used
centreon_clapi_backup_20260107_143022.txt
centreon_clapi_backup_20260106_020000.txt
What Gets Restored
The CLAPI import restores all Centreon configuration objects:
- Hosts and host templates
- Services and service templates
- Commands (check, notification, discovery)
- Time periods
- Contacts and contact groups
- Host groups and service groups
- Host categories and service categories
- SNMP traps
- Escalations
- Dependencies
- ACLs and access groups
- Pollers and broker configurations
The restoration does NOT include:
- RRD data (performance metrics)
- Event logs
- Historical acknowledgements
- Historical downtimes
Behavior on Conflicts
When importing:
- Existing objects with same name: Will be updated with values from backup
- New objects in backup: Will be created
- Objects not in backup: Will remain unchanged on the server
This means restoration is additive and updates - it does not delete objects that exist on the server but not in the backup.
Security Considerations
- Password Protection: Admin password is marked with
no_log: trueto prevent logging - Vault Storage: Admin password must be stored in Ansible Vault
- Destructive Operation: Imports will overwrite existing configuration objects
- Testing Recommended: Test restores in a non-production environment first
Error Handling
The role handles errors gracefully:
No Backup Files Found
TASK [Fail if no backup found]
fatal: [centreon]: FAILED! => {"msg": "No Centreon CLAPI backup files found in /media/nas_win_share/centreon/clapi"}
Import Failure
The task will fail if the centreon -i command returns a non-zero exit code. Check Centreon logs for details:
tail -f /var/log/centreon/centreon.log
Apply Configuration Failure
If APPLYCFG fails, check the Centreon Engine configuration:
/usr/sbin/centengine -v /etc/centreon-engine/centengine.cfg
Tags
This role does not define any tags. Use playbook-level tags if needed:
- hosts: centreon
roles:
- centreon_clapi_restore
tags:
- restore
- centreon
- disaster-recovery
Notes
- The role uses
changed_when: centreon_clapi_restore_import_status.rc == 0for proper idempotency tracking - APPLYCFG is applied to poller 1 (Central) - adjust if using remote pollers
- Restoration can take several minutes for large configurations
- The role displays the backup filename being used for transparency
Troubleshooting
”centreon: command not found”
Ensure Centreon CLAPI is installed and the centreon binary is in PATH. Typically at /usr/share/centreon/bin/centreon.
”Authentication failed” errors
Verify the vault_centreon_admin_password variable is correctly set. Test manually:
centreon -u admin -p 'password' -i /path/to/backup.txt
“No backup files found”
Verify:
- NAS is mounted:
mount | grep nas_win_share - Backup files exist:
ls -l /media/nas_win_share/centreon/clapi/ - Filename pattern matches:
centreon_clapi_backup_*.txt
Import succeeds but objects don’t appear
Run APPLYCFG manually to check for errors:
centreon -u admin -p 'password' -a APPLYCFG -v 1
Configuration validation errors
The imported configuration may have validation errors. Check:
/usr/sbin/centengine -v /etc/centreon-engine/centengine.cfg
Best Practices
- Test in non-production before restoring to production
- Backup current configuration before restoring (create a new CLAPI export)
- Verify poller connectivity after restoration
- Check service statuses to ensure monitoring resumed correctly
- Review broker configuration if using remote pollers
Related Roles
- centreon_clapi_backup: Creates the backup files this role restores
License
MIT
Author
Created for homelab infrastructure management.