dsexton18
(David Sexton)
October 4, 2024, 11:36am
1
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.
dsexton18
(David Sexton)
October 5, 2024, 1:02pm
3
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.
jiholland
(Jørn Ivar)
October 7, 2024, 1:30pm
4
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 }}"
dsexton18
(David Sexton)
October 8, 2024, 11:09am
5
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
~
system
(system)
Closed
November 7, 2024, 11:10am
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.