created: 2022-10-12T00:50:45.172Z

複数台の Raspberry Pi を ansible で管理するためのインベントリファイル/playbook

役割の違う複数の Raspberry Pi を ansible で管理するときのインベントリファイル(yaml)の書き方をメモ。

all:
  # 共通の変数を all 配下に vars で記述する
  vars:
    ansible_connection: ssh
    ansible_ssh_user: pi
    ansible_ssh_private_key_file: "./credentials/local_raspi_id_rsa"
    ansible_python_interpreter: /usr/bin/python3.9
  # children キーは設定ファイルの仕様上必須。この配下にマシンごとの変数やhostsなどを書く
  children:
    fileserver:
      hosts:
        fileserver.local
    recordserver:
      hosts:
        recordserver.local

参考

公式ドキュメントがとても丁寧でわかりやすかった。

その他

playbook ファイルは、マシンごとにファイルを用意するようにして、タイムゾーンや言語などの共通の処理を common_tasks.yml とかに切り出すと具合がよかった。

$ ls -1 ansible/*.yml
ansible/common_tasks.yml
ansible/fileserver.yml
ansible/recordserver.yml
ansible/hosts.yml
ansible/requirements.yml

本当は ansible の規約に沿ったディレクトリに配置すればいいのだろうけれども、それはもう少し管理台数が多くなってからの宿題にしておく。

詳説 データベース ―ストレージエンジンと分散データシステムの仕組み
[ad] 詳説 データベース ―ストレージエンジンと分散データシステムの仕組み
Alex Petrov, 小林 隆浩 (単行本(ソフトカバー))