From 08ee31514867accce125e8c49b372c50dbfcb32f Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Tue, 25 Apr 2017 10:06:42 +0200 Subject: [PATCH] etc-git: add a task to commit It can be invoked in pre/post tasks or anywhere in anther role. --- etc-git/README.md | 26 +++++++++++++++++++++++++- etc-git/defaults/main.yml | 2 ++ etc-git/tasks/commit.yml | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 etc-git/defaults/main.yml create mode 100644 etc-git/tasks/commit.yml diff --git a/etc-git/README.md b/etc-git/README.md index c1eb49c5..d0930e59 100644 --- a/etc-git/README.md +++ b/etc-git/README.md @@ -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" +``` diff --git a/etc-git/defaults/main.yml b/etc-git/defaults/main.yml new file mode 100644 index 00000000..2743375a --- /dev/null +++ b/etc-git/defaults/main.yml @@ -0,0 +1,2 @@ +--- +commit_message: Ansible run diff --git a/etc-git/tasks/commit.yml b/etc-git/tasks/commit.yml new file mode 100644 index 00000000..d7d1fbbf --- /dev/null +++ b/etc-git/tasks/commit.yml @@ -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