0

My objective is to check out a repository and all submodules within it using multiple deploy keys.

The git module recursive option does not work, it does not seem to support multiple key_files.

- name: Checkout foo repository
  git:
    repo: "git@github.com:org/foo.git"
    dest: /foo-path
    accept_hostkey: yes
    force: yes
    key_file: /home/test/.ssh/deploy_keys/foo
    version: "{{ branch }}"
    recursive: yes

Results in an error:

ERROR: Repository not found.\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists

Since i'm just passing one key_file to it, the sub repositories have different ones.


What seems to be my only current option is to skip the recursive option and for each repo/sub-module add a task to check it separately, an example would be below, using the above "foo" repository.

- name: Checkout bar within foo
  git:
    repo: "git@github.com:org/bar.git"
    dest: /foo-path/bar-path
    accept_hostkey: yes
    force: yes
    key_file: /home/test/.ssh/deploy_keys/bar
    version: "{{ commit }}"
    recursive: no
  become: no

However, this method doesn't prevent alterations to the 'bar' submodule, causing it to consistently show as having tracked changes.

Could someone clarify if I'm approaching this incorrectly, or if there's a viable solution available?

JazzCat
  • 4,243
  • 1
  • 26
  • 40
  • 2
    Remove for a moment Ansible from the problem: How do you run `git clone --recursive` with different deployment keys? – phd Aug 19 '23 at 14:57
  • I guess it is possible with .ssh/config creating different hostnames for each sub-repository, since ansible does not seem to process the config it doesnt work in this case Which forces me to use git@github.com instead of git@alias – JazzCat Aug 20 '23 at 11:51
  • 1
    In addition to `~/.ssh/config` listing all the keys with "virtual" (invented) hosts you also need `~/.gitconfig` that replaces (using `url…insteadOf`) URLs of every submodule with that invented hostnames. Possible but rather tricky, error-prone and hard to debug. – phd Aug 20 '23 at 12:13

0 Answers0