Make git role idempotent
This commit is contained in:
parent
ed6940e940
commit
72b240def6
2 changed files with 36 additions and 2 deletions
|
@ -18,6 +18,40 @@
|
||||||
src: ignore
|
src: ignore
|
||||||
dest: ~/.config/git/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
|
- name: Copy global gitconfig
|
||||||
template:
|
template:
|
||||||
src: gitconfig.j2
|
src: gitconfig.j2
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[user]
|
[user]
|
||||||
name = {{ ansible_facts['env']['USER'] }}@{{ ansible_hostname }}
|
name = {{ username }}
|
||||||
email = {{ git_email }}
|
email = {{ useremail }}
|
||||||
[pull]
|
[pull]
|
||||||
rebase = false
|
rebase = false
|
||||||
[alias]
|
[alias]
|
||||||
|
|
Loading…
Add table
Reference in a new issue