19
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AnsibleでSSH設定ファイルをVagrantfileと同じディレクトリにおいてpingする

Last updated at Posted at 2014-05-23

ありがたいAnsibleの日本語チュートリアル( http://yteraoka.github.io/ansible-tutorial/ )をやっていてpingでいきなり躓いた。

$ ansible -i hosts 192.168.33.12 -m ping
192.168.33.12 | FAILED => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue

-vvvvオプションをつけるとどうやらssh configが意図した場所ではなく、~/.ssh/configを読みに行っているようでした。
vagrantで作ったvmのssh設定ファイルは、Vagrantfileと同じ場所に置きたかったので調べてみました。
ansible.cfgで設定するようです:
http://docs.ansible.com/intro_configuration.html#ssh-args

以下、設定した結果です。
##各ファイルの中身
※Vagrantfileはチュートリアルのままなので省略

ansible.cfg
[ssh_connection]
ssh_args = -F ssh.config
ssh.config
Host node1
  HostName 127.0.0.1
  User vagrant
  Port 2001
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/yoccola/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL

Host node2
  HostName 127.0.0.1
  User vagrant
  Port 2002
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/yoccola/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL
hosts
[vagrant]
node1
node2

##確認
Host設定の名前でpingを叩いてみます。

$ ansible -i hosts node1 -m ping
node1 | success >> {
    "changed": false, 
    "ping": "pong"
}

allもいけました。

$ ansible -i hosts all -m ping
node1 | success >> {
    "changed": false, 
    "ping": "pong"
}

node2 | success >> {
    "changed": false, 
    "ping": "pong"
}

##参考
Ansible チュートリアル | Ansible Tutorial in Japanese
http://yteraoka.github.io/ansible-tutorial/

The Ansible Configuration File
http://docs.ansible.com/intro_configuration.html

19
17
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
19
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?