これはなに?
「Ansibleでサーバ設定を管理したい!」
macOSで始めていきます。
とりあえずインストールのみです。
環境
- macOS Catalina 10.15.6
- Homebrew 2.5.2
Ansibleのインストール
Homebrewを使用してインストールします。
brew install ansible
Ansible 2.9.13がインストールされました。
% brew info ansible
ansible: stable 2.9.13 (bottled), HEAD
Automate deployment, configuration, and upgrading
https://www.ansible.com/
/usr/local/Cellar/ansible/2.9.13 (18,363 files, 226.3MB) *
Poured from bottle on 2020-10-01 at 18:25:15
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/ansible.rb
License: GPL-3.0-or-later
インストールされたコマンド
以下のようなコマンドがインストールされました。
Ansible用語
よく見かけたわからない用語を並べてみました。
インベントリ
Ansibleで操作対象となるデバイスが記載されているファイルです。
あるいは操作対象デバイスです。
タスク
仕事です。操作対象デバイスに対して何か行うことです。
Playbook - プレイブック
デバイスの操作内容を記述するための言語です。
あるいはその言語で記述されたファイルです。
自分自身に接続してみる
ansible-console
コマンドを使用して、手元のmac上でタスクをひとつ実行してみます。
準備
あらかじめ、sshサーバを動くようにしておいてください。
設定 > 共有 からリモートログインを有効にします。
また、ssh鍵がなければ生成し、自分自身に鍵認証で接続できるようにしておいてください。
ssh-keygen -t ed25519
ssh-copy-id -i ~/.ssh/id_ed25519 localhost
鍵認証でログインできるか確認します。
ssh localhost
疏通確認タスクを実行する
ansible-console
にオプションをつけて起動します。
ansible-console --inventory localhost, --user 自分のログインID
--inventory
オプションの最後についているカンマはTYPOではないです。カンマがないと、ファイル名として扱われてしまうのです。
これで、ローカルホストでタスクを実行できます。
おもむろにping
と入力してみます。
このとき、sshのメッセージが表示されるかもしれません。Yesと回答します。
$ ping
[WARNING]: Platform darwin on host localhost is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python
interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
localhost | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
WARNINGが表示されていますが、Ansibleで操作できることが確認できました。