Help us understand the problem. What is going on with this article?

Macでansible-playbookを実行する時に~/.ssh/configの設定が参照されずUNREACHABLEとなる場合の対処法

More than 3 years have passed since last update.

MacでAnsibleを使うときに

$ ansible-playbook -i development site.yml --ask-pass

のようにパスワード認証のssh接続でplaybookを実行しようとすると、~/.ssh/configに設定を書いているホストへの接続が上手く行かず、以下のようなエラーが出たので対策を調べました。

fatal: [dev-test-server]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}

環境

ansible: 2.2.0
OS: OSX Yosemite

設定ファイル例

playbook実行ディレクトリ/development
[test-server]
dev-test-server

[development:children]
test-server

~/.ssh/config
Host dev-test-server
  HostName xxx.xxx.xxx.xxx
  Port 22
  User root

対処法

Macではopensshを使ってssh接続することになるので、-c sshオプションを使って接続するようです。さらに、パスワードを使う場合はsshpassを入れておく必要があるようです。
ただ、brew install sshpassでインストールしようとすると、セキュリティの問題でやめとけと言われるので、以下のコマンドでインストールします。

brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb

上記コマンドでsshpassが入ったら、以下のようにplaybookを実行します。 

$ ansible-playbook -i development site.yml -c ssh --ask-pass

これで~/.ssh/configの設定を反映してパスワード認証でplaybookが実行できました!

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした