Make git role idempotent

This commit is contained in:
flyingscorpio@clevo 2022-02-27 13:09:31 +01:00
parent ed6940e940
commit 72b240def6
2 changed files with 36 additions and 2 deletions

View file

@ -18,6 +18,40 @@
src: ignore
dest: ~/.config/git/ignore
- name: Check values for git_username
git_config:
scope: file
file: ~/.gitconfig
name: user.name
register: git_username
- name: Check values for git_useremail
git_config:
scope: file
file: ~/.gitconfig
name: user.email
register: git_useremail
- name: Reuse username
set_fact:
username: "{{ git_username.config_value }}"
when: git_username.config_value != ""
- name: Set new username
set_fact:
username: "{{ ansible_facts['env']['USER'] }}@{{ ansible_hostname }}"
when: git_username.config_value == ""
- name: Reuse useremail
set_fact:
useremail: "{{ git_useremail.config_value }}"
when: git_useremail.config_value != ""
- name: Set new useremail
set_fact:
useremail: "{{ git_email }}" # Set in vault
when: git_useremail.config_value == ""
- name: Copy global gitconfig
template:
src: gitconfig.j2

View file

@ -1,6 +1,6 @@
[user]
name = {{ ansible_facts['env']['USER'] }}@{{ ansible_hostname }}
email = {{ git_email }}
name = {{ username }}
email = {{ useremail }}
[pull]
rebase = false
[alias]