wildfly snapshot role
A role to manage WildFly configuration snapshots and provide automatic rollback on failure, using the JBoss CLI :take-snapshot operation for standalone mode.
Requirements
A running WildFly or JBoss EAP instance managed via systemd, with the management interface accessible.
Entrypoints
main / take_snapshot: take a configuration snapshot (auto-named or with a custom name)
list_snapshots: list all available configuration snapshots
delete_snapshot: delete a specific snapshot by name
restore_snapshot: stop the service, restore a snapshot file as the active configuration, and restart
apply_with_rollback: take a snapshot, apply CLI commands (or include a tasks file), and automatically restore on failure
Role Defaults
Variable |
Description |
Default |
|---|---|---|
|
WildFly installation directory |
|
|
WildFly installation directory used for CLI execution |
|
|
POSIX user account for WildFly |
|
|
POSIX group for WildFly |
|
|
WildFly instance name |
|
|
WildFly systemd service name |
|
|
Base directory prefix for standalone server |
|
|
Standalone server base directory |
|
|
Configuration directory path |
|
|
Active configuration file name |
|
|
Hostname for connecting to JBoss CLI |
|
|
Port for connecting to JBoss CLI |
|
|
Increment for jboss.socket.binding.port-offset |
|
|
Seconds to wait for JBoss CLI connection |
|
|
Optional name for the snapshot (auto-generated if empty) |
|
|
Whether privilege escalation is required |
|
|
Whether to deploy on a selinux enforcing target host |
|
Role Variables
Variable |
Description |
Required |
|---|---|---|
|
Name of the snapshot file to delete (for delete_snapshot entrypoint) |
Yes (delete_snapshot) |
|
Full path to the snapshot file to restore (for restore_snapshot entrypoint) |
Yes (restore_snapshot) |
|
List of JBoss CLI commands to execute with automatic rollback on failure |
Yes (apply_with_rollback) |
|
Path to an Ansible tasks file to include with automatic rollback on failure; mutually exclusive with wildfly_snapshot_apply_cli_commands |
No |
Example Playbooks
Take a Snapshot
Takes a timestamped configuration snapshot of a running WildFly instance.
- name: "Take a configuration snapshot"
hosts: all
collections:
- middleware_automation.wildfly
tasks:
- name: "Snapshot current configuration"
ansible.builtin.include_role:
name: wildfly_snapshot
vars:
wildfly_snapshot_jboss_home: /opt/wildfly/wildfly-41.0.0.Final/
# snapshot path is available in wildfly_snapshot_file_path
Take a Named Snapshot
- name: "Take a named snapshot"
hosts: all
collections:
- middleware_automation.wildfly
tasks:
- name: "Snapshot before maintenance"
ansible.builtin.include_role:
name: wildfly_snapshot
tasks_from: take_snapshot.yml
vars:
wildfly_snapshot_jboss_home: /opt/wildfly/wildfly-41.0.0.Final/
wildfly_snapshot_name: "pre-maintenance"
Apply Changes with Automatic Rollback
Applies a list of CLI commands with automatic rollback to the previous state if any command fails.
- name: "Apply configuration with rollback protection"
hosts: all
collections:
- middleware_automation.wildfly
tasks:
- name: "Configure datasource with rollback"
ansible.builtin.include_role:
name: wildfly_snapshot
tasks_from: apply_with_rollback.yml
vars:
wildfly_snapshot_jboss_home: /opt/wildfly/wildfly-41.0.0.Final/
wildfly_snapshot_apply_cli_commands:
- "/subsystem=datasources/data-source=ExampleDS:write-attribute(name=max-pool-size,value=50)"
- "/subsystem=logging/root-logger=ROOT:write-attribute(name=level,value=DEBUG)"
Manually Restore from a Snapshot
Stops the WildFly service, replaces the active configuration with the snapshot, and restarts.
- name: "Restore from snapshot"
hosts: all
collections:
- middleware_automation.wildfly
tasks:
- name: "Restore previous configuration"
ansible.builtin.include_role:
name: wildfly_snapshot
tasks_from: restore_snapshot.yml
vars:
wildfly_snapshot_jboss_home: /opt/wildfly/wildfly-41.0.0.Final/
wildfly_snapshot_restore_file: /opt/wildfly/wildfly-41.0.0.Final/standalone/configuration/standalone_xml_history/snapshot/20240101-120000000standalone.xml
List and Delete Snapshots
- name: "Manage snapshots"
hosts: all
collections:
- middleware_automation.wildfly
tasks:
- name: "List all snapshots"
ansible.builtin.include_role:
name: wildfly_snapshot
tasks_from: list_snapshots.yml
vars:
wildfly_snapshot_jboss_home: /opt/wildfly/wildfly-41.0.0.Final/
# available in wildfly_snapshot_list.names and wildfly_snapshot_list.directory
- name: "Delete a snapshot"
ansible.builtin.include_role:
name: wildfly_snapshot
tasks_from: delete_snapshot.yml
vars:
wildfly_snapshot_jboss_home: /opt/wildfly/wildfly-41.0.0.Final/
wildfly_snapshot_delete_name: "my-old-snapshot.xml"
YAML Configuration Extension
When the YAML configuration extension is enabled, :take-snapshot captures the effective XML configuration. YAML overlay files are applied at server boot time and are managed separately as templates by the wildfly_systemd role. If a rollback is needed due to YAML overlay issues, the overlay template files should be reverted independently.
License
GPL2