From a8d1c8268a252cd7cc5ff0ec0988b75277a0a5fe Mon Sep 17 00:00:00 2001 From: Jonathan Rosser Date: Wed, 29 May 2024 16:35:40 +0100 Subject: [PATCH] Allow openstack_hosts role to configure git safe.directory entries This is defaulted to '*" and will be undefined when a CI specific override is subsequently merged to the openstack-ansible repository. Change-Id: I1c1dc35d8d59db4ae2b6770a620d91548a8a3734 --- defaults/main.yml | 3 +++ tasks/main.yml | 1 - tasks/openstack_gitconfig.yml | 10 ++++++++++ templates/gitconfig.j2 | 7 +++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index e6357e4d..c48ceefd 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -212,3 +212,6 @@ openstack_hosts_systemd_networkd_networks: [] openstack_hosts_systemd_networkd_prefix: openstack-net openstack_hosts_systemd_services: [] openstack_hosts_systemd_slice: "openstack-hosts" + +openstack_hosts_git_safe_directories: + - "*" diff --git a/tasks/main.yml b/tasks/main.yml index 13ebc42b..275a7e82 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -169,7 +169,6 @@ apply: tags: - openstack_hosts-config - when: ansible_facts['hostname'] != 'aio1' - name: Including openstack_hosts_systemd tasks include_tasks: openstack_hosts_systemd.yml diff --git a/tasks/openstack_gitconfig.yml b/tasks/openstack_gitconfig.yml index 70314e7a..0a126408 100644 --- a/tasks/openstack_gitconfig.yml +++ b/tasks/openstack_gitconfig.yml @@ -29,6 +29,16 @@ value: "{{ 'git/' ~ _git_version.stdout.split(' ')[2] ~ ' (osa/' ~ lookup('env', 'OSA_VERSION') ~ '/' ~ component | default('undefined') ~ ')' }}" when: _git_version.rc == 0 +- name: Configure git safe directories + git_config: + scope: system + name: safe.directory + value: "{{ item }}" + with_items: "{{ openstack_hosts_git_safe_directories }}" + when: + - _git_version.rc == 0 + - openstack_hosts_git_safe_directories is defined + - name: Write git config when git is not installed template: src: gitconfig.j2 diff --git a/templates/gitconfig.j2 b/templates/gitconfig.j2 index 27e6d4bc..afe8f906 100644 --- a/templates/gitconfig.j2 +++ b/templates/gitconfig.j2 @@ -1,2 +1,9 @@ [http "https://opendev.org/"] userAgent = git/unknown (osa/{{ lookup('env', 'OSA_VERSION') }}/{{ component | default('undefined') }}) + +{% if openstack_hosts_git_safe_directories is defined %} +[safe] +{% for dir in openstack_hosts_git_safe_directories %} + directory {{ dir }} +{% endfor %} +{% endif %}