From 3b7ba8532f31d221c0708e2d6733bccdd3935f91 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 11 Sep 2023 18:01:37 +0200 Subject: etckeeper: manage the ignore list --- roles/etckeeper/handlers/commit.yml | 24 ++++++++++++++++++++++++ roles/etckeeper/handlers/commit_conf.yml | 24 ------------------------ roles/etckeeper/handlers/main.yml | 12 +++++++++++- 3 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 roles/etckeeper/handlers/commit.yml delete mode 100644 roles/etckeeper/handlers/commit_conf.yml (limited to 'roles/etckeeper/handlers') diff --git a/roles/etckeeper/handlers/commit.yml b/roles/etckeeper/handlers/commit.yml new file mode 100644 index 0000000..f48db8f --- /dev/null +++ b/roles/etckeeper/handlers/commit.yml @@ -0,0 +1,24 @@ +- name: Get list of modified files + become: true + ansible.builtin.shell: | + set -o pipefail && \ + git status --porcelain=v1 \ + | cut -c 4- \ + | grep -G -v '^{{ paths | map("regex_replace", "^/", "") | list | join("\|^") }}' + args: + chdir: /etc + register: git_status + changed_when: false + failed_when: git_status.rc not in [0, 1] + +- name: Fail if unexpected files were modified + ansible.builtin.fail: + msg: | + Unexpected files were modified: + {{ git_status.stdout }} + when: git_status.rc == 0 + +- name: etckeeper commit + become: true + ansible.builtin.command: | + etckeeper commit '{{ commit_msg }}' diff --git a/roles/etckeeper/handlers/commit_conf.yml b/roles/etckeeper/handlers/commit_conf.yml deleted file mode 100644 index 134e264..0000000 --- a/roles/etckeeper/handlers/commit_conf.yml +++ /dev/null @@ -1,24 +0,0 @@ -- name: Get list of modified files - become: true - ansible.builtin.shell: | - set -o pipefail && \ - git status --porcelain=v1 \ - | cut -c 4- \ - | grep -G -v '^etckeeper/etckeeper.conf' - args: - chdir: /etc - register: git_status - changed_when: false - failed_when: git_status.rc not in [0, 1] - -- name: Fail if unexpected files were modified - ansible.builtin.fail: - msg: | - Unexpected files were modified: - {{ git_status.stdout }} - when: git_status.rc == 0 - -- name: etckeeper commit - become: true - ansible.builtin.command: | - etckeeper commit 'configure etckeeper' diff --git a/roles/etckeeper/handlers/main.yml b/roles/etckeeper/handlers/main.yml index 9993ed5..ca6beaa 100644 --- a/roles/etckeeper/handlers/main.yml +++ b/roles/etckeeper/handlers/main.yml @@ -1,3 +1,13 @@ - name: Commit etckeeper.conf - ansible.builtin.include_tasks: commit_conf.yml + ansible.builtin.include_tasks: commit.yml + vars: + paths: [etckeeper/etckeeper.conf] + commit_msg: configure etckeeper listen: etckeeper_commit_conf + +- name: Commit .gitignore + ansible.builtin.include_tasks: commit.yml + vars: + paths: '{{ [".gitignore"] + etckeeper_ignored_paths + etckeeper_extra_ignored_paths }}' + commit_msg: configure ignored files + listen: etckeeper_commit_gitignore -- cgit v1.2.3