How to include vars files from a diffrent git repo

Any suggestions for how to include vars files that are in a different project?

IE say I have projecta with with some roles but I wish to put the variables in a different git project. The thought was this would allow me to write the roles and playbooks in projecta and put vars in a different project so the roles and playbooks can be used on different networks.

Maybe someone has a better idea but you could just check the other repo out locally using the git module ansible.builtin.git module – Deploy software (or files) from git checkouts — Ansible Community Documentation

Or reference the raw file url and download it using get_url ansible.builtin.get_url module – Downloads files from HTTP, HTTPS, or FTP to node — Ansible Community Documentation

One more way (that ive never actually done so YMMV) you could make the variable repo into a collection, and then make a lookup plugin that looks up the vars in that collection.

Thanks for the suggestion using ansible.builtin.git looks like a good option. I don’t see an option to clone a over https with a personal token.

I will look in to that more.

Gitlab example:

---
- name: Clone git repo.
  hosts: localhost
  gather_facts: false
  vars:
    git_token: "example"
    git_repo: "https://oauth2:{{ git_token }}@gitlab.example.com/example/example.git"
    git_version: main

  tasks:
    - name: Create temporary directory.
      ansible.builtin.tempfile:
        path: "/tmp"
        state: directory
      check_mode: false
      register: __git_temp_dir_output

    - name: Clone git repo.
      ansible.builtin.git:
        repo: "{{ git_repo }}"
        dest: "{{ __git_temp_dir_output['path'] }}"
        version: "{{ git_version }}"

I came up with similar solution. I added delegate_to: so the repo is only cloned the the local host.

- name: clone repo
  hosts: localhost
  vars:
    git_token_name: 'example'
    git_toke: '12345567899dkjdke'
    git_repo: 'example.com/example.git'

  tasks:

  - name: Git checkout
    delegate_to: localhost
    ansible.builtin.git:
      repo: "https://{{ git_token_name }}:{{ git_token }}:{{ git_repo }}"
      dest: ./example
      version: main
~