11.10. クラスター設定をエクスポートして RHEL システムロール Playbook を作成する
RHEL 9.6 以降では、ha_cluster
RHEL システムロールを使用して、クラスターの Corosync 設定を ha_cluster
変数にエクスポートし、その設定をロールに再度渡すことで、同じクラスターを再作成できるようになりました。クラスターの作成に ha_cluster
を使用しなかった場合、またはクラスターの元の Playbook にアクセスできない場合は、この機能を使用して、クラスターを作成するための新しい Playbook を構築できます。
ha_cluster
RHEL システムロールを使用してクラスターの設定をエクスポートしても、すべての変数がエクスポートされるわけではありません。これらの変数を考慮して、設定を手動で変更する必要があります。
エクスポートには次の変数が存在します。
-
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
-node_name
、corosync_addresses
、およびpcs_address
オプションのみが存在します。
次の変数はエクスポートに存在しません。
-
ha_cluster_hacluster_password
- これはロールの必須変数ですが、既存のクラスターから抽出することはできません。 -
ha_cluster_corosync_key_src
、ha_cluster_pacemaker_key_src
、およびha_cluster_fence_virt_key_src
- これらの変数には、Corosync キーと Pacemaker キーを含むファイルへのパスが含まれています。キー自体はエクスポートされないため、これらの変数もエクスポートには存在しません。これらのキーはクラスターごとに一意である必要があります。 -
ha_cluster_regenerate_keys
- 既存のキーを使用するか、新しいキーを生成するかを決定する必要があります。
現在のクラスター設定をエクスポートするには、ha_cluster
RHEL システムロールを実行し、ha_cluster_export_configuration: true
を設定します。これを行うと、ロールがクラスターまたは qnetd
ホストの設定を完了し、その設定を ha_cluster_facts
変数に格納したときに、エクスポートがトリガーされます。
デフォルトでは、ha_cluster_cluster_present
は true
に設定され、ha_cluster_qnetd.present
は false
に設定されています。これらの設定により、指定ホスト上のクラスターが再設定され、指定ホストから qnetd
設定が削除され、設定がエクスポートされます。既存の設定を変更せずにエクスポートをトリガーするには、次の設定を使用してロールを実行します。
- hosts: node1 vars: ha_cluster_cluster_present: null ha_cluster_qnetd: null ha_cluster_export_configuration: true roles: - linux-system-roles.ha_cluster
- hosts: node1
vars:
ha_cluster_cluster_present: null
ha_cluster_qnetd: null
ha_cluster_export_configuration: true
roles:
- linux-system-roles.ha_cluster
次の手順:
-
クラスターノード
node1
からクラスター設定をha_cluster_facts
変数にエクスポートします。 -
この Playbook を実行しても既存のクラスター設定が変更されないように、
ha_cluster_cluster_present
およびha_cluster_qnetd
変数を null に設定します。 -
Ansible デバッグモジュールを使用して、
ha_cluster_facts
の内容を表示します。 -
ha_cluster_facts
の内容を YAML 形式でコントロールノード上のファイルに保存し、それを基に Playbook を作成できるようにします。
前提条件
- コントロールノードと管理対象ノードの準備が完了している。
- 管理対象ノードで Playbook を実行できるユーザーとしてコントロールノードにログインしている。
-
管理対象ノードへの接続に使用するアカウントに、そのノードに対する
sudo
権限がある。 - エクスポートする設定を使用して、以前に高可用性クラスターを設定した。
- RHEL 9 でのコントロールノードの準備 の説明に従って、コントロールノードにインベントリーファイルを作成した。
手順
次の内容を含む Playbook ファイル (例:
~/playbook.yml
) を作成します。--- - 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"
--- - 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"
Copy to Clipboard Copied! サンプル Playbook で指定されている設定は次のとおりです。
hosts: node1
- エクスポートするクラスター情報を含むノード。
ha_cluster_cluster_present: null
- 指定ホスト上のクラスター設定を変更しないことを示すための設定。
ha_cluster_qnetd: null
- 指定ホスト上の qnetd ホスト設定を変更しないことを示すための設定。
ha_cluster_export_configuration: true
-
現在のクラスター設定をエクスポートし、
ha_cluster_info
モジュールによって生成されるha_cluster_facts
変数に格納するかどうかを決定する変数。 ha_cluster_facts
- エクスポートされたクラスター設定を格納する変数。
delegate_to: localhost
- エクスポートされた設定ファイルの場所としてコントロールノードを指定します。
content: "{{ ha_cluster_facts | to_nice_yaml(sort_keys=false) }"}
,dest: /path/to/file
,mode: "0640"
- YAML 形式の設定ファイルを /path/to/file にコピーし、ファイルの権限を 0640 に設定します。
コントロールノードの /path/to/file にエクスポートした変数を使用して、ご使用のシステム用の Playbook を作成します。
ha_cluster_hacluster_password
変数を追加する必要があります。この変数は必須の変数ですが、エクスポートには存在しないためです。システムで必要な場合は、ha_cluster_corosync_key_src
、ha_cluster_pacemaker_key_src
、ha_cluster_fence_virt_key_src
、およびha_cluster_regenerate_keys
変数を追加します。これらの変数はエクスポートされません。Playbook の構文を検証します。
ansible-playbook --syntax-check ~/playbook.yml
$ ansible-playbook --syntax-check ~/playbook.yml
Copy to Clipboard Copied! このコマンドは構文を検証するだけであり、有効だが不適切な設定から保護するものではないことに注意してください。
Playbook を実行します。
ansible-playbook ~/playbook.yml
$ ansible-playbook ~/playbook.yml
Copy to Clipboard Copied!