diff --git a/roles/git/tasks/main.yml b/roles/git/tasks/main.yml index 5d9d221..90b20ae 100644 --- a/roles/git/tasks/main.yml +++ b/roles/git/tasks/main.yml @@ -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 diff --git a/roles/git/templates/gitconfig.j2 b/roles/git/templates/gitconfig.j2 index 40eb31e..254f744 100644 --- a/roles/git/templates/gitconfig.j2 +++ b/roles/git/templates/gitconfig.j2 @@ -1,6 +1,6 @@ [user] - name = {{ ansible_facts['env']['USER'] }}@{{ ansible_hostname }} - email = {{ git_email }} + name = {{ username }} + email = {{ useremail }} [pull] rebase = false [alias]