0

AnsibleでEC2をプロビジョニングしています。自分で作成したrailsのコードをgithubのレポジトリに置いているので、自分のローカルPCからAnsibleのplaybookを叩いて、EC2からgit clone(git pullもしたい)してrailsのコードを持ってきたいのですが、下記のエラーが出ていてコードをEC2に持ってこれません。

{"changed": false, "cmd": "/usr/bin/git ls-remote '' -h refs/heads/HEAD", "failed": true, "msg": "Permission denied (publickey).\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.", "rc": 128, "stderr": "Permission denied (publickey).\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n", "stdout": "", "stdout_lines": []}

内容はpermission deniedされているのはわかるのですが、sshのキーを適切に設定できていないのだと思います。お手数ですが、AnsibleでEC2のgit cloneやgit pullをしたことある方・もしくは解決方法がわかる方がいらっしゃいましたら、その手順をご教示いただきたいです。

よろしくお願い致します。

1 件の回答 1

1

ec2 インスタンスから、 github にアクセスできる ssh キーでもってアクセスする必要がある様子です。そういった設定は行われていますでしょうか。

本家の Mikko Ohtamaa さんの回答 では、以下のようにすると、 git clone できる様子です。 ポイントは、

  1. github にアクセスできる ssh 秘密鍵を ec2 インスタンスに copy でもってアップロードして
  2. ansible git モジュールにて key_file で、アップロードした秘密鍵を指定する

ことの様子です。

- name: Creates .ssh directory for root
  sudo: yes
  file: path=/root/.ssh state=directory

# This public key is set on Github repo Settings under "Deploy keys"
- name: Upload the private key used for Github cloning
  sudo: yes
  copy: src=keys/github dest=/root/.ssh/github

- name: Correct SSH deploy key permissions
  sudo: yes
  file: dest=/root/.ssh/github mode=0600

- name: Deploy site files from Github repository
  sudo: yes
  git:
    repo: [email protected]:miohtama/foobar.git
    dest: /srv/django/foobar
    key_file: /root/.ssh/github
    accept_hostkey: yes
    force: yes

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。