11.7. Configuring a high availability cluster with resource constraints using system roles


When configuring a cluster, you can specify the behavior of the cluster resources to be in line with your application requirements. You can control the behavior of cluster resources by configuring resource constraints.

You can define the following categories of resource constraints:

The following example procedure uses the ha_cluster RHEL system role to create a high availability cluster that includes resource location constraints, resource colocation constraints, resource order constraints, and resource ticket constraints.

警告

The ha_cluster RHEL system role replaces any existing cluster configuration on the specified nodes. Any settings not specified in the playbook will be lost.

Prerequisites

Procedure

  1. Store your sensitive variables in an encrypted file:

    1. Create the vault:

      $ ansible-vault create ~/vault.yml
      New Vault password: <vault_password>
      Confirm New Vault password: <vault_password>
    2. After the ansible-vault create command opens an editor, enter the sensitive data in the <key>: <value> format:

      cluster_password: <cluster_password>
    3. Save the changes, and close the editor. Ansible encrypts the data in the vault.
  2. Create a playbook file, for example, ~/playbook.yml, with the following content:

    ---
    - name: Create a high availability cluster
      hosts: node1 node2
      vars_files:
        - ~/vault.yml
      tasks:
        - name: Create cluster with resource constraints
          ansible.builtin.include_role:
            name: redhat.rhel_system_roles.ha_cluster
          vars:
            ha_cluster_cluster_name: my-new-cluster
            ha_cluster_hacluster_password: "{{ cluster_password }}"
            ha_cluster_manage_firewall: true
            ha_cluster_manage_selinux: true
            # In order to use constraints, we need resources
            # the constraints will apply to.
            ha_cluster_resource_primitives:
              - id: xvm-fencing
                agent: 'stonith:fence_xvm'
                instance_attrs:
                  - attrs:
                      - name: pcmk_host_list
                        value: node1 node2
              - id: dummy-1
                agent: 'ocf:pacemaker:Dummy'
              - id: dummy-2
                agent: 'ocf:pacemaker:Dummy'
              - id: dummy-3
                agent: 'ocf:pacemaker:Dummy'
              - id: dummy-4
                agent: 'ocf:pacemaker:Dummy'
              - id: dummy-5
                agent: 'ocf:pacemaker:Dummy'
              - id: dummy-6
                agent: 'ocf:pacemaker:Dummy'
            # location constraints
            ha_cluster_constraints_location:
              # resource ID and node name
              - resource:
                  id: dummy-1
                node: node1
                options:
                  - name: score
                    value: 20
              # resource pattern and node name
              - resource:
                  pattern: dummy-\d+
                node: node1
                options:
                  - name: score
                    value: 10
              # resource ID and rule
              - resource:
                  id: dummy-2
                rule: '#uname eq node2 and date in_range 2022-01-01 to 2022-02-28'
              # resource pattern and rule
              - resource:
                  pattern: dummy-\d+
                rule: node-type eq weekend and date-spec weekdays=6-7
            # colocation constraints
            ha_cluster_constraints_colocation:
              # simple constraint
              - resource_leader:
                  id: dummy-3
                resource_follower:
                  id: dummy-4
                options:
                  - name: score
                    value: -5
              # set constraint
              - resource_sets:
                  - resource_ids:
                      - dummy-1
                      - dummy-2
                  - resource_ids:
                      - dummy-5
                      - dummy-6
                    options:
                      - name: sequential
                        value: "false"
                options:
                  - name: score
                    value: 20
            # order constraints
            ha_cluster_constraints_order:
              # simple constraint
              - resource_first:
                  id: dummy-1
                resource_then:
                  id: dummy-6
                options:
                  - name: symmetrical
                    value: "false"
              # set constraint
              - resource_sets:
                  - resource_ids:
                      - dummy-1
                      - dummy-2
                    options:
                      - name: require-all
                        value: "false"
                      - name: sequential
                        value: "false"
                  - resource_ids:
                      - dummy-3
                  - resource_ids:
                      - dummy-4
                      - dummy-5
                    options:
                      - name: sequential
                        value: "false"
            # ticket constraints
            ha_cluster_constraints_ticket:
              # simple constraint
              - resource:
                  id: dummy-1
                ticket: ticket1
                options:
                  - name: loss-policy
                    value: stop
              # set constraint
              - resource_sets:
                  - resource_ids:
                      - dummy-3
                      - dummy-4
                      - dummy-5
                ticket: ticket2
                options:
                  - name: loss-policy
                    value: fence

    The settings specified in the example playbook include the following:

    ha_cluster_cluster_name: <cluster_name>
    The name of the cluster you are creating.
    ha_cluster_hacluster_password: <password>
    The password of the hacluster user. The hacluster user has full access to a cluster.
    ha_cluster_manage_firewall: true
    A variable that determines whether the ha_cluster RHEL system role manages the firewall.
    ha_cluster_manage_selinux: true
    A variable that determines whether the ha_cluster RHEL system role manages the ports of the firewall high availability service using the selinux RHEL system role.
    ha_cluster_resource_primitives: <cluster_resources>
    A list of resource definitions for the Pacemaker resources configured by the ha_cluster RHEL system role, including fencing
    ha_cluster_constraints_location: <location_constraints>
    A variable that defines resource location constraints.
    ha_cluster_constraints_colocation: <colocation_constraints>
    A variable that defines resource colocation constraints.
    ha_cluster_constraints_order: <order_constraints>
    A variable that defines resource order constraints.
    ha_cluster_constraints_ticket: <ticket_constraints>
    A variable that defines Booth ticket constraints.
  3. Validate the playbook syntax:

    $ ansible-playbook --syntax-check --ask-vault-pass ~/playbook.yml

    Note that this command only validates the syntax and does not protect against a wrong but valid configuration.

  4. Run the playbook:

    $ ansible-playbook --ask-vault-pass ~/playbook.yml
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2026 Red Hat
トップに戻る