forked from evolix/ansible-roles
etc-git: commit in /usr/share/scripts when there's an active repository
This commit is contained in:
parent
a5a2c6e335
commit
0f8804a8ab
|
@ -16,6 +16,8 @@ The **patch** part changes incrementally at each release.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
* etc-git: commit in /usr/share/scripts when there's an active repository
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
|
@ -1,57 +1,27 @@
|
||||||
---
|
---
|
||||||
- name: is /etc clean?
|
|
||||||
command: git status --porcelain
|
|
||||||
args:
|
|
||||||
chdir: /etc
|
|
||||||
changed_when: False
|
|
||||||
register: git_status
|
|
||||||
when: not ansible_check_mode
|
|
||||||
ignore_errors: yes
|
|
||||||
tags:
|
|
||||||
- etc-git
|
|
||||||
- commit-etc
|
|
||||||
|
|
||||||
- debug:
|
- name: Is /etc a git repository
|
||||||
var: git_status
|
stat:
|
||||||
verbosity: 3
|
path: /etc/.git
|
||||||
tags:
|
register: _etc_git
|
||||||
- etc-git
|
|
||||||
- commit-etc
|
|
||||||
|
|
||||||
- name: fetch current Git user.email
|
- include: do_commit.yml
|
||||||
git_config:
|
vars:
|
||||||
name: user.email
|
git_folder: "/etc"
|
||||||
repo: /etc
|
|
||||||
register: git_config_user_email
|
|
||||||
ignore_errors: yes
|
|
||||||
tags:
|
|
||||||
- etc-git
|
|
||||||
- commit-etc
|
|
||||||
|
|
||||||
- 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-etc
|
|
||||||
|
|
||||||
- name: "/etc modifications are committed"
|
|
||||||
shell: "git add -A . && git commit -m \"{{ commit_message | mandatory }}\" --author \"{{ commit_author | mandatory }} <{{ commit_email | mandatory }}>\""
|
|
||||||
args:
|
|
||||||
chdir: /etc
|
|
||||||
register: etc_commit_end_run
|
|
||||||
when:
|
when:
|
||||||
- not ansible_check_mode
|
- _etc_git.stat.exists
|
||||||
- git_status.stdout
|
- _etc_git.stat.isdir
|
||||||
ignore_errors: yes
|
|
||||||
tags:
|
|
||||||
- etc-git
|
|
||||||
- commit-etc
|
|
||||||
|
|
||||||
- debug:
|
|
||||||
var: etc_commit_end_run
|
|
||||||
verbosity: 4
|
- name: Is /usr/share/scripts a git repository
|
||||||
tags:
|
stat:
|
||||||
- etc-git
|
path: /usr/share/scripts/.git
|
||||||
- commit-etc
|
register: _usr_share_scripts_git
|
||||||
|
|
||||||
|
- include: do_commit.yml
|
||||||
|
vars:
|
||||||
|
git_folder: "/usr/share/scripts"
|
||||||
|
when:
|
||||||
|
- _usr_share_scripts_git.stat.exists
|
||||||
|
- _usr_share_scripts_git.stat.isdir
|
||||||
|
|
64
etc-git/tasks/do_commit.yml
Normal file
64
etc-git/tasks/do_commit.yml
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
- name: "Remount /usr if needed"
|
||||||
|
include_role:
|
||||||
|
name: remount-usr
|
||||||
|
when: git_folder is match('/usr/.*')
|
||||||
|
|
||||||
|
|
||||||
|
- 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
|
||||||
|
- git_status.stdout
|
||||||
|
ignore_errors: yes
|
||||||
|
tags:
|
||||||
|
- etc-git
|
||||||
|
- commit
|
||||||
|
|
||||||
|
- debug:
|
||||||
|
var: commit_end_run
|
||||||
|
verbosity: 4
|
||||||
|
tags:
|
||||||
|
- etc-git
|
||||||
|
- commit
|
Loading…
Reference in a new issue