I want to git clone from Ansible EC2

Asked 2 years ago, Updated 2 years ago, 143 views

Provisioning EC2 in Ansible.I have my own rails code in the github repository, so I would like to hit the Ansible playbook from my local PC and get the rails code from EC2 by git clone (I also want to git pull), but I can't get the code to 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":[]}

I understand that the contents have been permission denied, but I think the ssh key has not been set properly.I'm sorry to trouble you, but if you've done a git clone or git pull for EC2, or if you know how to solve it, please let me know the procedure.

Thank you for your cooperation.

github ansible

2022-09-30 21:26

1 Answers

It appears that the ec2 instance needs to be accessed with an ssh key that can access github.Are those settings in place?

According to Mikko Ohtamaa's response, if you do the following, you can get a git clone. The point is

Here's how it goes.

-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


2022-09-30 21:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.