2021-04-08 16:07:19 +02:00
---
- name : "Remount /usr if needed"
include_role :
name : remount-usr
when : git_folder is match('/usr/.*')
2021-09-23 14:45:19 +02:00
- name : "stat {{ git_folder }}/.git/index.lock"
stat :
path : "{{ git_folder }}/.git/index.lock"
register : _index_lock
- name : index file is removed if old enough
file :
path : "{{ git_folder }}/.git/index.lock"
state : absent
when :
- _index_lock.stat.exists
- _index_lock.stat.mtime | int <= ((ansible_date_time.epoch | int) - etc_git_purge_index_lock_age | default(86400))
- etc_git_purge_index_lock_enabled
2021-04-08 16:07:19 +02:00
- name : "is {{ git_folder }} clean?"
command : git status --porcelain
args :
chdir : "{{ git_folder }}"
changed_when : False
register : git_status
when : not ansible_check_mode
ignore_errors : yes
tags :
- etc-git
- commit
- debug :
var : git_status
verbosity : 3
tags :
- etc-git
- commit
- name : fetch current Git user.email
git_config :
name : user.email
repo : "{{ git_folder }}"
register : git_config_user_email
ignore_errors : yes
tags :
- etc-git
- commit
- name : "set commit author"
set_fact :
commit_author : '{% if ansible_env.SUDO_USER is not defined %}root{% else %}{{ ansible_env.SUDO_USER }}{% endif %}'
commit_email : '{% if git_config_user_email.config_value is not defined or not git_config_user_email.config_value %}root@localhost{% else %}{{ git_config_user_email.config_value }}{% endif %}' # noqa 204
tags :
- etc-git
- commit
- name : "{{ git_folder }} modifications are committed"
shell : "git add -A . && git commit -m \"{{ commit_message | mandatory }}\" --author \"{{ commit_author | mandatory }} <{{ commit_email | mandatory }}>\""
args :
chdir : "{{ git_folder }}"
register : commit_end_run
when :
- not ansible_check_mode
2021-05-09 23:06:42 +02:00
- git_status.stdout | length > 0
2021-04-08 16:07:19 +02:00
ignore_errors : yes
tags :
- etc-git
- commit
- debug :
var : commit_end_run
verbosity : 4
tags :
- etc-git
- commit