はじめに
前回はAnsible
でBIG-IP
の初期設定を行ったので、今回も「F5自動化の取り組みとAnsiblex BIG-IP Playbookユースケースのご紹介」を参考に基本的な負荷分散設定をAnsible
で作成してみようと思います。
- 【前】BIG-IP Virtual Editionを使ってみる。(その4:Ansibleによる初期設定)
- 【次】BIG-IP Virtual Editionを使ってみる。(その6:Ansibleによる冗長化設定準備)
BIG-IPの負荷分散設定
BIG-IP
の負荷分散設定を行うためには、負荷分散対象となるNode
の設定、負荷分散対象となるNode
をまとめたPool
の設定、負荷分散を行うPool
や負荷分散用IPを定義するVirtual Server
の設定を行う必要があります。
今回は以下の様な名前の定義を設定していきます。
Ansible Playbookの作成
Node
、Pool
、Virtual Server
は個々にロールが分かれていたほうが管理し易いかと思うので、今回は個々の設定ごとにロールを分けて作成します。
ロール名 | 説明 |
---|---|
setup_bigip-node | ノードの設定を行うロール |
setup_bigip-pool | プールの設定を行うロール |
setup_bigip-virtual-server | Virtual Serverの設定を行うロール |
ロールの作成
前回と同様、ansible-galaxy
のコマンドでPlaybook
雛形を作成します。
cd roles/
ansible-galaxy init setup_bigip-node
ansible-galaxy init setup_bigip-pool
ansible-galaxy init setup_bigip-virtual-server
Node用tasksの作成
「F5自動化の取り組みとAnsiblex BIG-IP Playbookユースケースのご紹介」ではPool
のPool Menber
の設定を行う際に設定していますが、未作成のNode
をPool Menber
の設定で追加する場合、Node
の設定は初期設定となってしまいます。
今後、Node
に対して細かな設定を行うことも考え、今回はNode
モジュールを使って、先にNode
を作成するようにします。
---
# tasks file for setup_bigip-node
- name: BIG-IP 負荷分散ノードの作成
bigip_node:
name: "{{ item.name }}"
description: "{{ item.description }}"
host: "{{ item.host }}"
monitors: "{{ item.monitors }}"
ratio: "{{ item.ratio }}"
connection_limit: "{{ item.connection_limit }}"
rate_limit: "{{ item.rate_limit }}"
state: "present"
provider: "{{ bigip_provider }}"
delegate_to: "{{ bigip_delegate_to }}"
notify: save_config
loop: "{{ bigip_node }}"
Pool用tasksの作成
Pool
の設定には、箱となるPool
の設定と、Pool
に所属するNode
を指定するPool Member
の設定を行う必要があります。
Pool
の設定は今までと同様、Ansible
のPool
モジュールの説明を参考に、必要となる設定を記載していきます。
Pool Member
の設定は、作成したPool
にNode
を割り当てるため、割り当てるNode
数分、bigip_pool_member
モジュールを繰り返す必要があります。
「F5自動化の取り組みとAnsiblex BIG-IP Playbookユースケースのご紹介」では、マジック変数である、hostvars
とgroups
を使って、インベントリファイルに記載したホストグループのノードを繰り返す処理を行っていますが、今回作成したPlaybook
のように、Pool
の値も、Node
の値も変数で呼び出すようにした場合、hostvars
とgroups
を使用した方法ではPool
の変数値を思った通りに取得できなかったため、グループ変数にNode
の設定を記載するようにしました。
---
# tasks file for setup_bigip-pool
- name: BIG-IP 負荷分散プールの作成
bigip_pool:
partition: "Common"
name: "{{ item.name }}"
description: "{{ item.description }}"
monitors: "{{ item.monitors }}"
lb_method: "{{ item.lb_method }}"
priority_group_activation: "{{ item.priority_group_activation }}"
state: "present"
provider: "{{ bigip_provider }}"
delegate_to: "{{ bigip_delegate_to }}"
notify: save_config
loop: "{{ bigip_pool }}"
- name: BIG-IP 負荷分散プールメンバの作成
bigip_pool_member:
partition: "Common"
host: "{{ item.host }}"
name: "{{ item.name }}"
pool: "{{ item.pool }}"
port: "{{ item.port }}"
state: "present"
provider: "{{ bigip_provider }}"
delegate_to: "{{ bigip_delegate_to }}"
notify: save_config
loop: "{{ bigip_pool_member }}"
Virtual Server用tasksの作成
Virtual Server
のtasks
は特に難しいこともないため、Node
等と同じく、Ansible
のモジュールの説明を参考に作成します。
---
# tasks file for setup_bigip-virtual-server
- name: BIG-IP Virtual Serverの作成
bigip_virtual_server:
partition: "Common"
name: "{{ item.name }}"
description: "{{ item.description }}"
destination: "{{ item.destination }}"
port: "{{ item.port }}"
pool: "{{ item.pool }}"
enabled_vlans: "{{ item.enabled_vlans }}"
snat: "{{ item.snat }}"
profiles: "{{ item.profiles }}"
state: "present"
provider: "{{ bigip_provider }}"
delegate_to: "{{ bigip_delegate_to }}"
notify: save_config
loop: "{{ bigip_virtual_server }}"
コンフィグ保存用handlerの作成
前回と同様、設定変更が行われた場合にコンフィグをsave
する設定を行います。
作成した3つのロールすべてのhandlers
に以下の設定を行って下さい。
---
# handlers file for setup_bigip-xxxxx
- name: save_config
bigip_config:
save: "yes"
provider: "{{ bigip_provider }}"
delegate_to: "{{ bigip_delegate_to }}"
グループ変数の作成
前回作成したグループ変数に今回使用する変数を追記します。
各種設定は環境に合わせて修正して下さい。
---
(前回分設定省略)
# 負荷分散ノード設定
bigip_node:
- { name: "web01", description: "Web Server 1", host: "10.2.0.10", monitors: ["/Common/icmp"], ratio: "1", connection_limit: "0", rate_limit: "0" }
- { name: "web02", description: "Web Server 2", host: "10.2.0.11", monitors: ["/Common/icmp"], ratio: "1", connection_limit: "0", rate_limit: "0" }
# 負荷分散プール設定
bigip_pool:
- { name: "web_pool", description: "Web Server Pool", monitors: ["/Common/http"], lb_method: "round-robin", priority_group_activation: "0" }
# 負荷分散プールメンバ設定
bigip_pool_member:
- { pool: "web_pool", port: "80", host: "10.2.0.10", name: "web01" }
- { pool: "web_pool", port: "80", host: "10.2.0.11", name: "web02" }
# Virtual Server設定
bigip_virtual_server:
- { name: "web_vs1", description: "Virtual Server 1", destination: "10.1.0.10", port: "80", pool: "web_pool", enabled_vlans: "all", snat: "Automap", profiles: ["http"] }
ホスト変数の作成
今回はホスト単体に設定する内容は無いため、設定の追加は不要です。
グループごとのロール実行ファイルの作成
前回までの分含め、今回作成したsetup_bigip-node
、setup_bigip-pool
、setup_bigip-virtual-server
ロールを追記します。
---
- hosts: bigip
gather_facts: no
roles:
- setup_bigip-license
- setup_bigip-initconf
- setup_bigip-node
- setup_bigip-pool
- setup_bigip-virtual-server
全体のロール実行ファイルの作成
前回のファイルの内容と同じになるので割愛。
Playbookの依存関係設定
今回作成した3つのロールは、上で紹介した図のような構成となるため、setup_bigip-node
→setup_bigip-pool
→setup_bigip-virtual-server
の順に作成するよう依存関係を設定します。
metaの作成
依存関係の設定を行うため、setup_bigip-pool
とsetup_bigip-virtual-server
のロールに以下の設定を行います。
(略)
# dependencies: [] ←コメントアウトする。
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
dependencies:
- setup_bigip-node
(略)
# dependencies: [] ←コメントアウトする。
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
dependencies:
- setup_bigip-node
- setup_bigip-pool
Ansibleの実行
作成したロールを実行していきます。
ansible-playbook -i hosts-all site.yml
おわりに
今回は一通りの負荷分散の設定を行いました。
次回は冗長化設定を行ってみようと思います。