git from github

I want to do a git archive from git hub private repo or a shallow clone

But I don't see how to specify the username and password. If I use the ssh: protocol I can add the username. How do I specify the password.

thanks

Eric:

I would recommend using ssh agent forwarding to check out a git repo. You’ll need to use the “ssh” connection and enable agent forwarding on your local machine, as well as ensuring that the remote git repo has your ssh public key.

Lorin

thanks

I have no idea how to do that but tomorrow I will search google and figure it out. I use mac osx.

thanks

Loving ansible…

Eric

You’re in luck! Mac OS X has great support for ssh agent forwarding, it automatically starts up an ssh agent for you when you first log in to your machine. You can check it’s running by doing:

echo $SSH_AUTH_SOCK

You should see something like:
/tmp/launch-MYGNdH/Listeners

You’ll need to add “ForwardAgent yes” to your ~/.ssh/config file on your mac.

Lorin

Or alternatively you can just specify what key to use to checkout by setting GIT_SSH via the “environment:” keyword in Ansible.

http://stackoverflow.com/questions/3496037/how-to-specify-which-ssh-key-to-use-within-git-for-git-push-in-order-to-have-git

Hi Lorin,

I’m trying to set this up exactly as you describe, but have not had any luck unfortunately :frowning:

My ~/.ssh/config works fine when I use ssh manually - I can type “ssh my_host_shortname” and connect to my machine and then I can pull from github because I have ForwardAgent properly set.

But I’ve seen zero evidence that ansible is using any information in ~/.ssh/config

Here’s my ansible inventory file: http://pastebin.com/6e7Ue2VA

I can run “ansible all -m ping” and it works fine, but if I run “ansible all -a ‘ssh -T git@github.com’” then I get a permission denied error because my ssh agent was not forwarded.

Any ideas?

Thank you!

  • Daniel

For ansible, ssh-add to load ssh keys in your host machine first.
Then use “ssh” as connection type with forwarding enabled.

Such as:
$ ssh-add

$ export ANSIBLE_TRANSPORT=“ssh”
$ export ANSIBLE_SSH_ARGS=“-o ForwardAgent=yes”

See manual for ssh-add for running the agent.

Rodney

Adding ANSIBLE_SSH_ARGS=“-o ForwardAgent=yes” worked!

Why did ANSIBLE_SSH_ARGS=“-A” not work? That’s the option I use when using the normal ssh command line…

Finally - is there a way I can add this to my config file so that I don’t have to have an environment variable set?

I tried adding this to /etc/ansible/ansible.cfg:

[defaults]
ansible_ssh_args=“-o ForwardAgent=yes”

But now I get this error when connecting:

ec2-54-xxx-43-201.us-west-2.compute.amazonaws.com | FAILED => failed to transfer file to /command:

command-line: line 0: Bad configuration option: ControlPersist
lost connection

Thanks for your help.

Hey all,

Pardon the thread resurrection but I have a related question.

I wonder if you would have the time to expand it a little for me? I’m attempting to get our Continuous Integration / Deployment system, Strider to run an Ansible playbook to deploy our application. The deploy process will run as a user, Ansible. As part of the deployment process it attempts to grab the latest from a private github repository.

At the moment, I’m attempting to do that using the following:

git: “repo=git@github.com:Username/private_repo.git dest={{ tempdir.stdout }} depth=1”$
environment:$
GIT_SSH: /home/ansible/deployment_key$

That is failing though and reading out the entire key. I’ve looked at this post (http://stackoverflow.com/questions/3496037/how-to-specify-which-ssh-key-to-use-within-git-for-git-push-in-order-to-have-git) on Stackoverflow and can’t work out how to integrate the suggested solution.

Any suggestions?

Thanks, Dan.

SWEEEEETTTT! This worked for me too! Anyway I can add this to my ansible.cfg permanently?

Yep, see http://ansibleworks.com/docs/intro_configuration.html#ssh-args