Reputation: 5672
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...
Upvotes: 6
Views: 1967
Reputation: 5648
~/.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
Upvotes: 1