はじめに
前回、"ansibleでBIG-IPを制御してみよう①"で環境を作ったので、ansibleでBIG-IPの基本的な設定とバーチャルサーバの作成をしてみる。
検証環境
VMWare ESXi 5.5
CentOS Linux release 7.4.1708 (Core)
ansible 2.4.0.0
BIG-IP VE trial 12.1.2 Build 0.0.249
playbookのディレクトリ、ファイルは、前回の記事を引き継ぐ。
ansible2.4用python環境 : /opt/ansible2.4
playbookの格納先 : /opt/playbook
ansibleの実行ユーザ : ansibleuser
初期設定
ブラウザで管理画面にログインすると、初期セットアップの画面が出てくる。ここで設定をしないと、通常の設定画面が表示されない。今回、ansibleで設定しようとしているので、この画面は必要ないので、表示されないようにしつつ、初期設定を行う。
Playbookの作成
ホスト名、タイムゾーンを設定し、初期セットアップ画面の表示をなくす。
$ vi init.yml
- hosts: localhost
become: no
gather_facts: no
tasks:
- name: Set the hostname of the BIG-IP
bigip_hostname:
hostname: "bigip.localhost.localdomain"
server: "{{ bigip_ip }}"
user: "{{ bigip_user }}"
password: "{{ bigip_passwd }}"
validate_certs: "no"
- name: set timezone
bigip_device_ntp:
timezone: Asia/Tokyo
server: "{{ bigip_ip }}"
user: "{{ bigip_user }}"
password: "{{ bigip_passwd }}"
validate_certs: "no"
- name: Disabling the BIG-IP Setup utility
bigip_sys_global:
gui_setup: "disabled"
server: "{{ bigip_ip }}"
user: "{{ bigip_user }}"
password: "{{ bigip_passwd }}"
validate_certs: "no"
state: "present"
Playbookの実行
$ ansible-playbook -i hosts init.yml
インターフェイスに、Vlan , IPアドレスの設定
inteface 1.1 に、
・ tag無しのvlan
・ ipアドレス(172.23.141.70/16)
・ 受け付けるサービスがall
で設定してみます。
Playbookの作成
$ vi vlan.yml
- hosts: localhost
become: no
gather_facts: no
tasks:
- name: Add vlan as untagged to interface 1.1
bigip_vlan:
untagged_interface: 1.1
name: "vlan11"
server: "{{ bigip_ip }}"
user: "{{ bigip_user }}"
password: "{{ bigip_passwd }}"
validate_certs: "no"
state: "present"
- name: Create Self IP to vlan11 / Allow all services access to this Self IP
bigip_selfip:
name: "vlan11ip"
address: "172.23.141.70"
netmask: "255.255.0.0"
vlan: "vlan11"
allow_service:
- all
server: "{{ bigip_ip }}"
user: "{{ bigip_user }}"
password: "{{ bigip_passwd }}"
validate_certs: "no"
state: "present"
Playbookの実行
$ ansible-playbook -i hosts vlan.yml
Virtual Serverの作成
VirtualServerを作成します。その為に、node/pool/pool memberを作成します。合わせて、iRULEも作成して適用していきます。
作成するVirtualServerは以下のような設定(抜粋)。
- VirtualServer : virtual-webserver
- Destination Addres : 172.23.141.72
- profile : http
- pool : webserver-pool
- pool_member :
- node(host) : webserver1
- ip : 172.23.141.71
- node(host) : webserver1
- pool_member :
- iRULE : replace_server_header
- /opt/playbook/files/irule_replace_server_header.txt
iRULEをローカルに作成
まずは、ローカルファイルにiRULEを書きます。後で、このファイルをBIG-IPに適用します。
$ vi files/irule_replace_server_header.txt
when HTTP_RESPONSE {
HTTP::header replace Server dummy
}
※HTTPレスポンスヘッダのServerの値を、"dummy"の文字列に置き換えるiRULE
Playbookの作成
$ vi virtualserver.yml
- hosts: localhost
become: no
gather_facts: no
tasks:
- name: Add node
bigip_node:
partition: "Common"
host: "172.23.141.71"
name: "webserver1"
monitors:
- /Common/icmp
server: "{{ bigip_ip }}"
user: "{{ bigip_user }}"
password: "{{ bigip_passwd }}"
validate_certs: "no"
state: "present"
- name: Add pool
bigip_pool:
name: "webserver-pool"
partition: "Common"
monitors:
- /Common/http
monitor_type: and_list
server: "{{ bigip_ip }}"
user: "{{ bigip_user }}"
password: "{{ bigip_passwd }}"
validate_certs: "no"
state: "present"
- name: Add pool member
bigip_pool_member:
pool: "webserver-pool"
partition: "Common"
host: "webserver1"
port: 80
description: "web server"
connection_limit: 100
rate_limit: 50
ratio: 1
server: "{{ bigip_ip }}"
user: "{{ bigip_user }}"
password: "{{ bigip_passwd }}"
validate_certs: "no"
state: "present"
- name: Add the iRule contained in local file to the LTM module
bigip_irule:
content: "{{ lookup('template', '/opt/playbook/files/irule_replace_server_header.txt') }}"
module: "ltm"
name: "replace_server_header"
server: "{{ bigip_ip }}"
user: "{{ bigip_user }}"
password: "{{ bigip_passwd }}"
validate_certs: "no"
state: "present"
- name: Add Virtual Server
bigip_virtual_server:
partition: Common
name: virtual-webserver
destination: 172.23.141.72
port: 80
pool: webserver-pool
snat: Automap
all_profiles:
- http
all_rules:
- replace_server_header
server: "{{ bigip_ip }}"
user: "{{ bigip_user }}"
password: "{{ bigip_passwd }}"
validate_certs: "no"
state: "present"
設定の保存
- playbookの実行
$ ansible-playbook -i hosts save.yml
最後に
基本的な設定、バーチャルサーバの作成はできたので、次回はnode/pool member/virtual serverの閉塞をやろうかと思います。
この記事に関して
この記事が提供している情報に関しては、合法性、正確性、安全性等、いかなる保証もされません。この記事を利用することによって生ずるいかなる損害に対しても一切責任を負いません。