tpaexec provision
=================

プロビジョニングは、クラスターに必要なインスタンスとその他のリソースを作成します。

このプロセスの正確な詳細は、クラスターの構成中に選択したアーキテクチャたとえば
 :ref:`M1 <M1>`  とプラットフォームたとえば :ref:`awscliを使用してボリューム属性を変更する <awscliを使用してボリューム属性を変更する>` 
の両方に依存します。

プロビジョニングステージの最後に、基本的なオペレーティングシステムがインストールされた必要な数のインスタンスができます。TPAは、ssh経由でアクセスできますルートにsudoを使用します。

前提条件
--------

クラスターをプロビジョニングする前に、 :ref:`tpaexec configure <Cluster configuration>` を使用してクラスター構成を生成する必要があります

そして、必要に応じてconfig.ymlを編集して構成を微調整します。

プラットフォーム依存の追加の手順が必要になる場合があります。たとえば、AWS
APIアクセスキーペアを取得してEC2インスタンスをプロビジョニングするか、LXDまたはDockerをセットアップしてコンテナをプロビジョニングする必要があります。詳細については、プラットフォームのドキュメントを参照してください。

クイックスタート
----------------

.. code:: bash

   [tpa]$ tpaexec provision ~/clusters/speedy

   PLAY [Provision cluster]  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  **** **
   ...

   TASK [Set up EC2 instances]  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  *** 
   changed: [localhost] => (item=us-east-1:quirk)
   changed: [localhost] => (item=us-east-1:keeper)
   changed: [localhost] => (item=us-east-1:zealot)
   changed: [localhost] => (item=us-east-1:quaver)
   changed: [localhost] => (item=us-east-1:quavery)
   ...

   TASK [Generate ssh_config file for the cluster]  ****  ****  ****  ****  ****  ****  ****  ****  *** 
   changed: [localhost]

   PLAY RECAP  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  ****  **** 
   localhost                  : ok=128  changed=20   unreachable=0    failed=0   

   real    2m19.386s
   user    0m51.819s
   sys     0m27.852s

このコマンドは、大量の出力を生成しますさらに詳細な出力が必要な場合は、コマンドに\ ``-v``
、\ ``-vv``
などを追加します。出力は、クラスターディレクトリの\ ``ansible.log``
にも記録されます。これは、環境変数\ ``ANSIBLE_LOG_PATH``
を目的のログファイルのパスと名前に設定することによりオーバーライドできます。

エラーなしで完了した場合は、 :ref:`tpaexec deploy <tpaexec deploy>` の実行に進んでソフトウェアのインストールと構成を行うことができます。

オプション
----------

クラウドインスタンスをプロビジョニングするときは、インスタンスが、それらを担当する人間まで直接追跡可能であることを確認することが特に重要です。デフォルトでは、TPAは\ ``tpaexec provision``
を実行しているユーザーのログイン名が所有するものとしてEC2インスタンスにタグ付けします。

名前を変更するには\ ``--owner <name>``
を指定しますたとえば、ユーザー名がpostgresやec2-userのような汎用的なものである場合。イニシャル、「名、姓」、またはその他を一意に識別するために使用できます。

指定した他のオプションはAnsibleに渡されます。

インスタンスへのアクセス
------------------------

プロビジョニングが完了すると、インスタンスにSSH接続できるようになります。インスタンスが起動してSSHホストキーをインストールできるようにするために少し遅延した後。上記の出力に示されているように、tpaexecは使用できるssh_configファイルを生成します。

.. code:: bash

   [tpa]$ cd ~/clusters/speedy
   [tpa]$ cat ssh_config
   Host *
       Port 22
       IdentitiesOnly yes
       IdentityFile "id_speedy"
       UserKnownHostsFile "known_hosts tpa_known_hosts"
       ServerAliveInterval 60

   Host quirk
       User admin
       HostName 54.227.207.189
   Host keeper
       User admin
       HostName 34.229.111.196
   Host zealot
       User admin
       HostName 18.207.108.211
   Host quaver
       User admin
       HostName 54.236.36.251
   Host quavery
       User admin
       HostName 34.200.214.150
   [tpa]$ ssh -F ssh_config quirk
   Linux quirk 4.9.0-6-amd64 #1 SMP Debian 4.9.82-1+deb9u3 (2018-03-02) x86_64

   The programs included with the Debian GNU/Linux system are free software;
   the exact distribution terms for each program are described in the
   individual files in /usr/share/doc/*/copyright.

   Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
   permitted by applicable law.
   Last login: Sat Aug  4 12:31:28 2018 from 136.243.148.74
   admin@quirk:~$ sudo -i
   root@quirk:~# 

プロビジョニングの直後に :ref:`tpaexec deploy <tpaexec deploy>` を実行できます。インスタンスが起動するまで、必要なだけ待機します。インスタンスが起動するのを待ったり、展開を開始する前にssh接続したりする必要はありません。

生成されたファイル
------------------

プロビジョニングプロセス中に、多数の新しいファイルがクラスターディレクトリに作成されます。

.. code:: bash

   [tpa]$ ls ~/clusters/speedy
   total 240
   - rw-r--r-- 1 ams ams 193098 Aug  4 17:59 ansible.log
   drwxr-xr-x 2 ams ams   4096 Aug  4 17:38 commands
   - rw-r--r-- 1 ams ams   1442 Aug  4 17:54 config.yml
   lrwxrwxrwx 1 ams ams     51 Aug  4 17:38 deploy.yml -> 
                                /opt/EDB/TPA/architectures/M1/deploy.yml
   drwxr-xr-x 2 ams ams   4096 Aug  4 17:38 hostkeys
   - rw------- 1 ams ams   1675 Aug  4 17:38 id_speedy
   - rw------- 1 ams ams   1438 Aug  4 17:38 id_speedy.ppk
   - rw-r--r-- 1 ams ams    393 Aug  4 17:38 id_speedy.pub
   drwxr-xr-x 4 ams ams   4096 Aug  4 17:50 inventory
   - rw-r--r-- 1 ams ams   2928 Aug  4 17:50 tpa_known_hosts
   - rw-r--r-- 1 ams ams    410 Aug  4 17:50 ssh_config
   - rw-r--r-- 1 ams ams   3395 Aug  4 17:59 vars.json
   drwxr-xr-x 2 ams ams   4096 Aug  4 17:38 vault

私たちはすでにssh *configファイルを研究しました。これは、 \`id*
\*\ ``filesクラスター用に生成されたSSHキーペアと``\ tpa_known_hosts\ ``インスタンスにインストールされた``\ hostkeys/\`
の署名を参照します。

``vars.json`` ファイルは、\ ``--cached``
の後続の呼び出しで\ ``tpaexec provision``
によって使用される場合があります。

``inventory/``
ディレクトリには、静的および動的インベントリーファイルと、config.ymlのグループおよびホスト変数定義が含まれています。

.. code:: bash

   [tpa]$ cat inventory/00-speedy
   [tag_Cluster_speedy]
   quirk ansible_host=54.227.207.189 node=1 platform=aws
   keeper ansible_host=34.229.111.196 node=2 platform=aws
   zealot ansible_host=18.207.108.211 node=3 platform=aws
   quaver ansible_host=54.236.36.251 node=4 platform=aws
   quavery ansible_host=34.200.214.150 node=5 platform=aws

   [tpa]$ cat inventory/group_vars/tag_Cluster_speedy/01-speedy.yml 
   cluster_name: speedy
   cluster_tag: tag_Cluster_speedy
   postgres_version: 15
   tpa_version: v23.10-22-g30c1d5ea
   tpa_2q_repositories: []
   vpn_network: 192.168.33.0/24

   [tpa]$ cat inventory/host_vars/zealot/02-topology.yml
   role:

   - barman

   - log-server

   - openvpn-server

   - monitoring-server

   - witness
   upstream: quirk

config.ymlの変数を変更し、プロビジョニングを再実行すると、これらのファイルが更新されます。構成を変更しない場合、何も起こりません。
config.ymlに新しいインスタンスを追加して再実行すると、既存のインスタンスに影響を与えることなく新しいインスタンスが表示されます。
