LoginSignup
11
11

More than 5 years have passed since last update.

Macにhomebrewでansibleをインストールした際のインベントリファイル(inventory file)に関して

Last updated at Posted at 2015-12-04

Macでansibleを実行しようとした際に、inventory fileがどこにあるのか気にあったので確認。

ソフトウェア バージョン
Vagrant 1.7.2
Ansible 1.9.4

Mac上にansibleを導入する場合は以下を参考

Mac から Vagrant1.7 へ ansibleを実行した際のメモ(SSH Error解決含む)

AnsibleをMacから実行

CentOSなどで、Ansibleをインストールした際は、/etc/ansible/hostsの場所にinventory host fileが置かれているというのは、よく目にする。

では、Macどうか。

$ ansible 192.168.30.11 -m ping                                                                               
ERROR: Unable to find an inventory file, specify one with -i ?

もちろん、inventory fileを指定しないとエラーがでる。
しかし、今回はMacにbrewでインストールしたため、inventory fileのデフォルトの場所が分からなかったで、対応してみた。

解決方法

$ mkdir /usr/local/etc/ansible
$ vi /usr/local/etc/ansible/hosts

対象となるIPアドレスを記述

/usr/local/etc/ansible/hosts
192.168.30.11

再度、実行

$ ansible 192.168.30.11 -m ping                                
192.168.111.111 | success >> {
    "changed": false,
    "ping": "pong"
}

無事に解決。

デフォルトのinventory fileの場所に関して

ansible --help

helpを実行すると、inventory fileを指定するオプション部分に以下のように書かれている。

-i INVENTORY, --inventory-file=INVENTORY
                      specify inventory host file
                      (default=/usr/local/etc/ansible/hosts)

結構、悩んだのだが、ヘルプを最初にちゃんと読めばよかった。

11
11
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
11
11