Last active
September 4, 2024 10:42
-
-
Save devynspencer/effa29af449c46477ac71213210e7043 to your computer and use it in GitHub Desktop.
Example playbook for cloning a private git repository with Ansible.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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://[email protected]/someone/example-repo.git | |
key_file=/root/.ssh/id_rsa.github | |
dest=/opt/example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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----- | |
MIIEogIBAAKCAQEAzoyI5fvatHZ8kjtDLr7uOtoc7dziWVAPsf6oLzzZ1Bbs7e0u | |
t1IR/eTakDY/NwQi9o5y0MDSDnSwPyaV4heMY6eY2lABUFU+NenW+0P53akqdGc8 | |
ejXhhv3gbfJ+sNmdU6CNtm2lxlZ2UwJVlRTwvLARiUN/OnPudGQYD4qJ1uZQy9Lj | |
5j+mJMMiCOV0zX3HVrlAQHTgnUPe+yIzbC9J9rtjhBquNFLrsxgkzgWYcmUMEp+i | |
wO9xHOOetekrP1qV+TmkM9pSeCUjL0uBeSDtsfEKbC9He5EmLMdayDsrxtCRG8GG | |
EzJK3vdn4ITTqTdf82YhPhbcSwogw0/LzYrcAQIDAQABAoIBAGiXHVNoHy02uonJ | |
3JE1OakvfWqtaSjUs73sN/oDlEIjgcJRUlCeDGJGmq5f6c7QF2xGYbl3imari/vO | |
bCN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8EGacRRMmqMGsuJIckWMPA1avC2h5C+w7BZx851HZJvuWt7YmcEuvx1KP7G3bU+h | |
fVQWuUcj3Cto/US5H2fE7v9+PmRsAgPe5Ozw5N+WAu12rLV//Aw= | |
-----END RSA PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# templates/ssh_config.j2 | |
{{ ansible_managed | comment }} | |
Host github.com | |
IdentityFile /root/.ssh/id_rsa.github | |
IdentitiesOnly yes |
Double check your repository url. Looks a bit odd at a glance.
Sent from a mobile device!
… On 23 Dec 2019, at 21:51, Sven Davison ***@***.***> wrote:
new to ansible. i can remote into the host and just 'git clone ' and it pulls the repo no problems. what am i missing?
fatal: [104.248.127.247]: FAILED! => {"changed": false, "cmd": "/usr/bin/git clone --origin origin ***@***.***:svendavison/ansible-for-keeps.git' /data/ansible-crap/repos", "msg": "ssh: Could not resolve hostname github.com:svendavison: Name or service not known\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.", "rc": 128, "stderr": "ssh: Could not resolve hostname github.com:svendavison: Name or service not known\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n", "stderr_lines": ["ssh: Could not resolve hostname github.com:svendavison: Name or service not known", "fatal: Could not read from remote repository.", "", "Please make sure you have the correct access rights", "and the repository exists."], "stdout": "Cloning into '/data/ansible-crap/repos'...\n", "stdout_lines": ["Cloning into '/data/ansible-crap/repos'..."]}
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
Yep. They fixed it. I blindly took a couple examples and didn’t sanitize/validate them. I’m good now thanks!
…-Sven Davison
(sent from my iPhone)
On Dec 24, 2019, at 3:07 AM, Stephen Wolff ***@***.***> wrote:
Double check your repository url. Looks a bit odd at a glance.
Sent from a mobile device!
> On 23 Dec 2019, at 21:51, Sven Davison ***@***.***> wrote:
>
>
> new to ansible. i can remote into the host and just 'git clone ' and it pulls the repo no problems. what am i missing?
>
> fatal: [104.248.127.247]: FAILED! => {"changed": false, "cmd": "/usr/bin/git clone --origin origin ***@***.***:svendavison/ansible-for-keeps.git' /data/ansible-crap/repos", "msg": "ssh: Could not resolve hostname github.com:svendavison: Name or service not known\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.", "rc": 128, "stderr": "ssh: Could not resolve hostname github.com:svendavison: Name or service not known\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n", "stderr_lines": ["ssh: Could not resolve hostname github.com:svendavison: Name or service not known", "fatal: Could not read from remote repository.", "", "Please make sure you have the correct access rights", "and the repository exists."], "stdout": "Cloning into '/data/ansible-crap/repos'...\n", "stdout_lines": ["Cloning into '/data/ansible-crap/repos'..."]}
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub, or unsubscribe.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
it worked for me thanks a lot
Help me with this one ansible/ansible#67416
how to write playbook to git repo cloneing, i am facing errors
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
new to ansible. i can remote into the host and just 'git clone ' and it pulls the repo no problems. what am i missing? I've disable strickHostKeyChecking and still no joy via ansible.
fatal: [104.248.127.247]: FAILED! => {"changed": false, "cmd": "/usr/bin/git clone --origin origin 'ssh:********@github.com:svendavison/ansible-for-keeps.git' /data/ansible-crap/repos", "msg": "ssh: Could not resolve hostname github.com:svendavison: Name or service not known\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.", "rc": 128, "stderr": "ssh: Could not resolve hostname github.com:svendavison: Name or service not known\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n", "stderr_lines": ["ssh: Could not resolve hostname github.com:svendavison: Name or service not known", "fatal: Could not read from remote repository.", "", "Please make sure you have the correct access rights", "and the repository exists."], "stdout": "Cloning into '/data/ansible-crap/repos'...\n", "stdout_lines": ["Cloning into '/data/ansible-crap/repos'..."]}