Skip to content

Instantly share code, notes, and snippets.

@devops0925
Forked from devynspencer/ansible-github.yml
Last active January 27, 2020 08:11
Show Gist options
  • Select an option

  • Save devops0925/4e617ed3cdf2afb7057b9f6db68a53e9 to your computer and use it in GitHub Desktop.

Select an option

Save devops0925/4e617ed3cdf2afb7057b9f6db68a53e9 to your computer and use it in GitHub Desktop.
Example playbook for cloning a private git repository with Ansible.
---
hosts: all
tasks:
- name: add github ssh key
copy: >
src=files/id_rsa.github
dest=/root/.ssh/id_rsa.github
owner=root
group=root
mode=0600
- name: configure ssh to use ansible key for github.com
template: >
src=templates/ssh_config.j2
dest=/root/.ssh/config
owner=root
group=root
mode=0644
- name: clone a private repository
git: >
repo=ssh://git@github.com/someone/example-repo.git
key_file=/root/.ssh/id_rsa.github
dest=/opt/example
# Obviously this is an example private key. Replace with your own ssh private key
# and ensure it has been added to your GitHub account.
# files/id_rsa.github
-----BEGIN RSA PRIVATE KEY-----
MII
HSXR5/AnG7SCCt9MvfogMrPFE+/5LJr9+cSFHdNV99cOfhpNzP0=
-----END RSA PRIVATE KEY-----
# templates/ssh_config.j2
{{ ansible_managed | comment }}
Host github.com
IdentityFile /root/.ssh/id_rsa.github
IdentitiesOnly yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment