etc-git: add a task to commit

It can be invoked in pre/post tasks or anywhere in anther role.
This commit is contained in:
Jérémy Lecour 2017-04-25 10:06:42 +02:00 committed by Jérémy Lecour
parent 7fa9c4adf0
commit 08ee315148
3 changed files with 60 additions and 1 deletions

View file

@ -4,4 +4,28 @@ Put /etc under Git version control.
## Tasks
Everything is in the `tasks/main.yml` file.
The main part (installation and configuration) is in the `tasks/main.yml` file.
There is also an independant task that can be executed to commit changes made in `/etc/.git`, for example when a playbook is run :
```
- name: My Splendid Playbook
[…]
pre_tasks:
- include_role:
name: etc-git
task_from: commit.yml
vars:
commit_message: "Ansible pre-run my splendid playbook"
roles :
[…]
post_tasks:
- include_role:
name: etc-git
task_from: commit.yml
vars:
commit_message: "Ansible pre-run my splendid playbook"
```

View file

@ -0,0 +1,2 @@
---
commit_message: Ansible run

33
etc-git/tasks/commit.yml Normal file
View file

@ -0,0 +1,33 @@
---
- 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:
- commit-etc
- debug:
var: git_status
verbosity: 3
tags:
- commit-etc
- name: /etc modifications are committed
shell: "git add -A . && git commit -m \"{{ commit_message | mandatory }}\""
args:
chdir: /etc
register: etc_commit_end_run
when: not ansible_check_mode and git_status.stdout != ""
ignore_errors: yes
tags:
- commit-etc
- debug:
var: etc_commit_end_run
verbosity: 4
tags:
- commit-etc