11.9. Exporting a cluster configuration to create a RHEL system role playbook
You can use the ha_cluster RHEL system role to export the Corosync configuration of a cluster into ha_cluster variables that can be fed back to the role to recreate the same cluster.
If you did not use ha_cluster to create your cluster, or if you do not have access to the original playbook for the cluster, you can use this feature to build a new playbook for creating the cluster.
When you export a cluster’s configuration by using the ha_cluster RHEL system role, not all of the variables are exported. You must manually modify the configuration to account for these variables.
The following variables are present in the export:
-
ha_cluster_cluster_present -
ha_cluster_start_on_boot -
ha_cluster_cluster_name -
ha_cluster_transport -
ha_cluster_totem -
ha_cluster_quorum -
ha_cluster_node_options- Only thenode_name,corosync_addressesandpcs_addressoptions are present. -
ha_cluster_enable_repos -
ha_cluster_enable_repos_resilient_storage -
ha_cluster_manage_firewall -
ha_cluster_manage_selinux -
ha_cluster_install_cloud_agents -
ha_cluster_pcs_permission_list -
ha_cluster_resource_primitives -
ha_cluster_resource_groups -
ha_cluster_resource_clones -
ha_cluster_resource_bundles
The following variables are not present in the export:
-
ha_cluster_hacluster_password- This is a mandatory variable for the role but it cannot be extracted from existing clusters. -
ha_cluster_corosync_key_src,ha_cluster_pacemaker_key_srcandha_cluster_fence_virt_key_src- These variables should contain paths to files with Corosync and Pacemaker keys. Since the keys themselves are not exported, these variables are not present in the export either. These keys should be unique for each cluster. -
ha_cluster_regenerate_keys- You should decide whether to use existing keys or to generate new ones. -
ha_cluster_hacluster_qdevice_password- Specifies the password for theha_clusteruser on a quorum device. This is a required setting when using a quorum device to avoid manual intervention. It cannot be extracted from existing clusters. -
ha_cluster_fence_agent_packages- A list of fence agent packages to install. -
ha_cluster_extra_packages- Specifies any extra packages to be installed on the cluster nodes. -
ha_cluster_use_latest_packages- When set totrue, the system role will use the latest available packages for the cluster. -
ha_cluster_pcsd_public_key_src,ha_cluster_pcsd_private_key_src- These variables should contain paths to TLS certificate and private key forpcsd. Since the certificate and key themselves are not exported, these variables are not present in the export either. -
ha_cluster_pcsd_certificates- When this variable is set, the certificate RHEL system role is used internally to create the private key and certificate forpcsd. It cannot be extracted from existing clusters.
To export the current cluster configuration, run the ha_cluster RHEL system role and set ha_cluster_export_configuration: true. This triggers the export once the role finishes configuring a cluster or a qnetd host and stores it in the ha_cluster_facts variable.
By default, ha_cluster_cluster_present is set to true and ha_cluster_qnetd.present is set to false. These settings will reconfigure your cluster on the specified hosts, remove qnetd configuration from the specified hosts, and then export the configuration. To trigger the export without modifying an existing configuration, run the role with the following settings:
- hosts: node1
vars:
ha_cluster_cluster_present: null
ha_cluster_qnetd: null
ha_cluster_export_configuration: true
roles:
- linux-system-roles.ha_cluster
The following procedure:
-
Exports the cluster configuration from cluster node
node1into theha_cluster_factsvariable. -
Sets the
ha_cluster_cluster_presentandha_cluster_qnetdvariables to null to ensure that running this playbook does not modify the existing cluster configuration. -
Uses the Ansible debug module to display the content of
ha_cluster_facts. -
Saves the contents of
ha_cluster_factsto a file on the control node in a YAML format for you to write a playbook around it.
Prerequisites
- You have prepared the control node and the managed nodes.
- You are logged in to the control node as a user who can run playbooks on the managed nodes.
-
The account you use to connect to the managed nodes has
sudopermissions for these nodes. - You have previously configured the high availability cluster with the configuration to export.
- You have created an inventory file on the control node, as described in Preparing a control node on RHEL 10.
Procedure
Create a playbook file, for example,
~/playbook.yml, with the following content:--- - name: Export high availability cluster configuration hosts: node1 Tasks: - name: Export configuration that does not modify existing cluster ansible.builtin.include_role: name: redhat.rhel_system_roles.ha_cluster vars: ha_cluster_cluster_present: null ha_cluster_qnetd: null ha_cluster_export_configuration: true - name: Print ha_cluster_info_result variable ansible.builtin.debug: var: ha_cluster_facts - name: Save current cluster configuration to a file delegate_to: localhost ansible.builtin.copy: content: "{{ ha_cluster_facts | to_nice_yaml(sort_keys=false) }}" dest: /path/to/file mode: "0640"The settings specified in the example playbook include the following:
hosts: node1- A node containing the cluster information to export.
ha_cluster_cluster_present: null- Setting to indicate that the cluster configuration will not be changed on the specified host.
ha_cluster_qnetd: null- Setting to indicate that the qnetd host configuration will not be changed on the specified host.
ha_cluster_export_configuration: true-
A variable that determines whether to export the current cluster configuration and store it in the
ha_cluster_factsvariable, which is generated by theha_cluster_infomodule. ha_cluster_facts- A variable that contains the exported cluster configuration.
delegate_to: localhost- Specifies the control node as the location for the exported configuration file.
content: "{{ ha_cluster_facts | to_nice_yaml(sort_keys=false) }"},dest: /path/to/file,mode: "0640"Copies the configuration file in a YAML format to /path/to/file, setting the file permissions to 0640.
For details about all variables used in the playbook, see the
/usr/share/ansible/roles/rhel-system-roles.ha_cluster/README.mdfile on the control node.
Validate the playbook syntax:
$ ansible-playbook --syntax-check ~/playbook.ymlNote that this command only validates the syntax and does not protect against a wrong but valid configuration.
Run the playbook:
$ ansible-playbook ~/playbook.ymlAfter you have exported the current cluster configuration, you can write a playbook for your system using the variables you exported to /path/to/file on the control node.
You must add the
ha_cluster_hacluster_passwordvariable, as it is a required variable but is not present in the export. Optionally, add theha_cluster_corosync_key_src,ha_cluster_pacemaker_key_src,ha_cluster_fence_virt_key_src, andha_cluster_regenerate_keysvariables if your system requires them. These variables are never exported.