Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git clone hangs in Ansible

Tags:

git

ssh

ansible

What I've tried:

1) Copy private key from local machine to server and clone with it:

- name: clone repo
  sudo: yes
  git: repo={{ app_repo }} dest={{ app_repo_dir }} accept_hostkey=true key_file={{ssh_key}} version=master force=yes

But it hangs. As I understand this issue occurs 'cause key has passphrase.

2) Use ForwardAgent in ansible.cfg:

[ssh_connection]
ssh_args = -o ForwardAgent=yes

But for connection to server I use not standard ssh 22 port.

How can I setup passphrase for key for git clone task in Ansible? Or any other ways to clone remote repository using Ansible?

P.S. Yes, I can try to remove passphrase from key. But security aspects...

like image 714
Suvitruf - Andrei Apanasik Avatar asked Jan 16 '16 01:01

Suvitruf - Andrei Apanasik


People also ask

How to clone Git repository with Ansible?

You need to set up the Ansible inventory so that you can clone a git repository with ansible. Ansible inventory file is located in /etc/ansible/hosts .

How to install the latest version of Ansible on CentOS?

You should install EPEL (Extra Packages for Enterprise Linux) at first so that you can install the latest version on Ansible in CentOS, RedHat, SUSE, and Fedora using the below command: You need to set up the Ansible inventory so that you can clone a git repository with ansible. Ansible inventory file is located in /etc/ansible/hosts .

How do I connect Ansible to GitHub using SSH key?

SSH key generated on the Ansible Node. The private key will remain on the Ansible remote node, but you’ll add the public key on GitHub for authentication. An inventory file set up and one or more hosts already configured to run Ansible command and playbooks on.

What is the ansible inventory?

The Ansible inventory is a file that contains information about the remote servers you wish to manage with Ansible. By default, the file is located in /etc/ansible/hosts. Create this file manually if it does not exit. Save the file.


1 Answers

  1. ~/.ssh/config :

    Host canada.host.xxxx

    HostName canada.host.xxxx

    Port 2233

    User guest

    IdentityFile ~/.ssh/id_rsa.special

  2. 2.

Copy private key from local machine to server and clone with it:

  • name: clone repo sudo: yes git: repo={{ app_repo }} dest={{ app_repo_dir }} accept_hostkey=true key_file={{ssh_key}}

This is Copy private key from local machine to server and clone with it:

- name: Put artifact to target
  sudo: yes
  copy: src="{{ app_repo_dir }}" dest="{{ app_repo_dir }}"

- name: clone repo
  sudo: yes
  git: repo={{ app_repo }} dest={{ app_repo_dir }} accept_hostkey=true key_file={{ssh_key}} version=master force=yes

PS: Maybe you should use local_action?

ansible-playbook -vvv will show you the problem

like image 109
Valeriy Solovyov Avatar answered Sep 19 '22 22:09

Valeriy Solovyov