LoginSignup
5
5

More than 3 years have passed since last update.

[Ansible] macOSで始めるAnsible (1)

Last updated at Posted at 2020-10-03

これはなに?

「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

単一タスクのPlaybookを定義し、実行します。


ansible-config

Ansibleの設定を表示します。


ansible-connection

リモートデバイスへ接続します。
(直接使うことはないかな?)


ansible-console

Ansibleタスクを実行するREPL(Read-eval-print-loop)です。


ansible-doc

プラグインのドキュメンテーションツールです。


ansible-galaxy

共有レポジトリ(既定では https://galaxy.ansible.com/ )にあるロールを操作します。


ansible-inventory

作成したインベントリを表示します。


ansible-playbook

複数個のPlaybookを実行します。


ansible-pull

VCS(Version Control System)からPlaybookを取得します。
プルモードで使います。


ansible-test

テスト実行ツールです。


ansible-vault

データファイルを暗号化/複合化するユーティリティです。

Ansible用語

よく見かけたわからない用語を並べてみました。

インベントリ

Ansibleで操作対象となるデバイスが記載されているファイルです。
あるいは操作対象デバイスです。

タスク

仕事です。操作対象デバイスに対して何か行うことです。

Playbook - プレイブック

デバイスの操作内容を記述するための言語です。
あるいはその言語で記述されたファイルです。

自分自身に接続してみる

ansible-consoleコマンドを使用して、手元のmac上でタスクをひとつ実行してみます。

準備

あらかじめ、sshサーバを動くようにしておいてください。
設定 > 共有 からリモートログインを有効にします。

image.png

また、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で操作できることが確認できました。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5