# How to include vars files from a diffrent git repo

**URL:** <https://forum.ansible.com/t/how-to-include-vars-files-from-a-diffrent-git-repo/9673>\
**Category:** Get Help\
**Tags:** role, playbook, awx\
**Created:** [October 4, 2024, 11:36am UTC](https://forum.ansible.com/t/how-to-include-vars-files-from-a-diffrent-git-repo/9673 "2024-10-04T11:36:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsexton18](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dsexton18/32/4952_2.png) [@dsexton18](https://forum.ansible.com/u/dsexton18)\
**Post date:** [October 4, 2024, 11:36am UTC](https://forum.ansible.com/t/how-to-include-vars-files-from-a-diffrent-git-repo/9673/1 "2024-10-04T11:36:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mikemorency](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mikemorency/32/2672_2.png) [@mikemorency](https://forum.ansible.com/u/mikemorency)\
**Post date:** [October 4, 2024, 4:41pm UTC](https://forum.ansible.com/t/how-to-include-vars-files-from-a-diffrent-git-repo/9673/2 "2024-10-04T16:41:02Z")

</div>

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](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/git_module.html)

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](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/get_url_module.html)

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.

---

<div class="post-metadata">

**Author:** ![dsexton18](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dsexton18/32/4952_2.png) [@dsexton18](https://forum.ansible.com/u/dsexton18)\
**Post date:** [October 5, 2024, 1:02pm UTC](https://forum.ansible.com/t/how-to-include-vars-files-from-a-diffrent-git-repo/9673/3 "2024-10-05T13:02:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [October 7, 2024, 1:30pm UTC](https://forum.ansible.com/t/how-to-include-vars-files-from-a-diffrent-git-repo/9673/4 "2024-10-07T13:30:38Z")

</div>

> [@dsexton18](#):
>
> I don’t see an option to clone a over https with a personal token.

Gitlab example:

```yaml
---
- 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 }}"

```

---

<div class="post-metadata">

**Author:** ![dsexton18](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dsexton18/32/4952_2.png) [@dsexton18](https://forum.ansible.com/u/dsexton18)\
**Post date:** [October 8, 2024, 11:09am UTC](https://forum.ansible.com/t/how-to-include-vars-files-from-a-diffrent-git-repo/9673/5 "2024-10-08T11:09:59Z")

</div>

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

```auto
- 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
~                       

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 7, 2024, 11:10am UTC](https://forum.ansible.com/t/how-to-include-vars-files-from-a-diffrent-git-repo/9673/6 "2024-11-07T11:10:27Z")

</div>

Closed on November 7, 2024, 11:10am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
