Git clone private repo using controller's private ssh key.

This commit is contained in:
2025-03-17 12:15:02 +01:00
commit 2678dd2c5b

View File

@@ -0,0 +1,29 @@
# An example of cloning a private Git repo that requires ssh key.
# The controller machine has the required key.
# The key is transfered to the target machine.
# Note: a more secure alternative is to use forwarding!
- name: Ensure .ssh directory exists
ansible.builtin.file:
path: /home/{{ user }}/.ssh
state: directory
mode: "0700"
owner: "{{ user }}"
group: "{{ user }}"
- name: Copy private key
ansible.builtin.copy:
src: ~/.ssh/id_rsa
dest: /home/{{ user }}/.ssh/id_rsa
mode: "0600"
owner: "{{ user }}"
group: "{{ user }}"
- name: Clone config Git repo
ansible.builtin.git:
repo: "ssh://git@git.netclew.com/SomeRepo/HomeServerConfigs.git"
dest: /tmp/myrepo
version: main # Change to the correct branch or tag
accept_hostkey: yes
# Ensure local user is used, not sudo
become_user: "{{ user }}"