LoginSignup
6
1

More than 5 years have passed since last update.

Mac で Ansible 使ってたら SSH エージェントフォワーディングで詰まった話

Posted at

結論

Mac 使ってて Ansible で SSH エージェントフォワーディング効かないときは -c ssh オプションつけるべし
(teratail で教えていただきました)

困っていたこと

Mac から Linux マシンを Ansible で構築してたんだけどどうにもこうにも SSH エージェントフォワーディングがうまくいってなくて git clone とかそこら辺が全くできなかった。

fatal: [xxx.xxx.xxx.xxx]: FAILED! => {"changed": true, "cmd": ["ssh-add", "-l"], "delta": "0:00:00.004968", "end": "2016-12-21 11:44:41.814838", "failed": true, "invocation": {"module_args": {"_raw_params": "ssh-add -l", "_uses_shell": false, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 2, "start": "2016-12-21 11:44:41.809870", "stderr": "Could not open a connection to your authentication agent.", "stdout": "", "stdout_lines": [], "warnings": []}

原因

Mac で Ansible 使ってると SSH に openssl ではなく paramiko がデフォルトで使用されるため…らしい。
なお、環境は

  • Mac OSX 10.10
  • Python 2.7.10
  • Ansible 2.1.1.0

対策

ansible.cfg に設定を書いて実行

$ cat /etc/ansible/ansible.cfg
[defaults]
transport = ssh
# ↑これで -c ssh オプションをしているのと同義

[ssh_connection]
ssh_args = -o ForwardAgent=yes
# ↑ SSH エージェントフォワーディングを有効に

タスク

---
- name: test ssh-agent
  command: ssh-add -l
  become: no

実行結果

{"changed": true, "cmd": ["ssh-add", "-l"], "delta": "0:00:00.023313", "end": "2016-12-22 12:11:02.230611", "invocation": {"module_args": {"_raw_params": "ssh-add -l", "_uses_shell": false, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 0, "start": "2016-12-22 12:11:02.207298", "stderr": "", "stdout": "2048 hogehoge (RSA)", "stdout_lines": ["2048 fugafuga (RSA)"], "warnings": []}

できた :tada:

6
1
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
6
1