解説
rolesの構成は以下の通りです。紹介するplaybookのroleではdefaults、ハンドラー、metaなどを使用しないため説明を割愛します。
tasksについて
site.ymlで読み込んだvirtual-server.ymlのrolesアトリビュートを用いることでroleが読み込まれます。rolesとは謂わばplaybookの管理・運用を上手くするための方法です。例えば、1つのplaybookにlinux, windows, mysqlの設定を記述したコードを書くと、1つの製品のバージョンアップの度にplaybookのメンテナンスが必要です。そうした事態を防ぐために、linux構築用のrole、windows構築用のrole、mysql構築用のrole、といったように機能毎にplaybookのtaskを分けておくことで管理・運用をスマートにします。これはAnsibleのBest Practiceに則った手法です。
rolesフォルダの配下は必ずrolesアトリビュートで定義した名前と同一である必要があります。つまり、rolesで定義したroleをAnsible実行時に読み込みます。
※virtual-server.ymlより引用
—
– name: Create Virtual Server
hosts: bigip
gather_facts: no
serial: 1
roles:
– Create_vertual_server_with_SNAT →これと同じフォルダ名にする
Ansible実行時には必ずroles/*/tasks/main.ymlが読み込まれます。このファイルにはtaskのみを記述します。以下は今回紹介するplaybookにおけるmain.ymlの中身です。ここに全て記述しても良いですが、ブログ管理人の場合ですと、各オブジェクト毎にtaskを分けて管理したいため、import_tasksで更に別ファイルに記述したtaskを読み込んでいます。
—
# device情報の取得
– name: Collect device information
import_tasks: 00_device_info.yml
tags: device_info
# http monitor作成
– name: configure monitor_http
import_tasks: 01_monitor_http.yml
tags: monitor_http
# icmp monitor作成
– name: configure monitor_icmp
import_tasks: 02_monitor_icmp.yml
tags: monitor_icmp
# node作成
– name: configure node
import_tasks: 11_node.yml
tags: node
# pool作成
– name: configure pool
import_tasks: 12_pool.yml
tags: pool
# 作成したpoolにメンバー追加
– name: add poolmember
import_tasks: 13_poolmember.yml
tags: poolmember
# SecureNATPOOL作成
– name: configure SNATPool
import_tasks: 14_snatpool.yml
tags: snatpool
# # iFile登録
# – name: configure upload iFile
# import_tasks: 21_ifile.yml
# tags: ifile
# iRule作成
– name: configure iRule
import_tasks: 22_irule.yml
tags: iRule
# HTTP Profile作成
– name: configure HTTP Profile
import_tasks: 31_http-profile.yml
tags: http-profile
# TCP Profile作成
– name: configure TCP Profile
import_tasks: 32_tcp-profile.yml
tags: tcp-profile
# PersistenceProfile作成
– name: configure Persistent Profile
import_tasks: 33_persistent-profile.yml
tags: persistent_profile
# 秘密鍵と署名付き証明書の登録(未作成)
# https://docs.ansible.com/ansible/latest/collections/f5networks/f5_modules/bigip_ssl_key_cert_module.html#ansible-collections-f5networks-f5-modules-bigip-ssl-key-cert-module
# 署名付き証明書の登録(未作成)
# https://docs.ansible.com/ansible/latest/collections/f5networks/f5_modules/bigip_ssl_certificate_module.html#ansible-collections-f5networks-f5-modules-bigip-ssl-certificate-module
# client SSL Profile作成
– name: configure Client SSL Profile
import_tasks: 34_client_sslprofile.yml
tags: Client_ssl_Profile
# Virtual Server作成
– name: configure virtual server
import_tasks: 41_virtualserver.yml
tags: virtual_server
コメント