forked from evolix/ansible-roles
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:
parent
7fa9c4adf0
commit
08ee315148
|
@ -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"
|
||||
```
|
||||
|
|
2
etc-git/defaults/main.yml
Normal file
2
etc-git/defaults/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
commit_message: Ansible run
|
33
etc-git/tasks/commit.yml
Normal file
33
etc-git/tasks/commit.yml
Normal 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
|
Loading…
Reference in a new issue