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...
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 .
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 .
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.
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.
~/.ssh/config :
Host canada.host.xxxx
HostName canada.host.xxxx
Port 2233
User guest
IdentityFile ~/.ssh/id_rsa.special
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With