aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-09-11 12:50:37 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-09-11 13:47:17 +0200
commitf9cc864d0482b8077179b346bfe9ad83a2327deb (patch)
tree6d731bb71e56456609709e9fd2f88559d074ada2
parentetckeeper: configure git remote as well (diff)
downloadinfra-ansible-f9cc864d0482b8077179b346bfe9ad83a2327deb.tar.gz
infra-ansible-f9cc864d0482b8077179b346bfe9ad83a2327deb.zip
etckeeper: commit etckeeper.conf changes
Diffstat (limited to '')
-rw-r--r--roles/etckeeper/handlers/commit_conf.yml24
-rw-r--r--roles/etckeeper/handlers/main.yml3
-rw-r--r--roles/etckeeper/tasks/main.yml2
3 files changed, 29 insertions, 0 deletions
diff --git a/roles/etckeeper/handlers/commit_conf.yml b/roles/etckeeper/handlers/commit_conf.yml
new file mode 100644
index 0000000..a9eb409
--- /dev/null
+++ b/roles/etckeeper/handlers/commit_conf.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 '^etckeeper/etckeeper.conf'
+ args:
+ chdir: /etc
+ register: etckeeper_modified_files
+ changed_when: false
+ failed_when: etckeeper_modified_files.rc not in [0, 1]
+
+- name: Fail if unexpected files were modified
+ ansible.builtin.fail:
+ msg: |
+ Unexpected files were modified:
+ {{ etckeeper_modified_files.stdout }}
+ when: etckeeper_modified_files.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
new file mode 100644
index 0000000..9993ed5
--- /dev/null
+++ b/roles/etckeeper/handlers/main.yml
@@ -0,0 +1,3 @@
+- name: Commit etckeeper.conf
+ ansible.builtin.include_tasks: commit_conf.yml
+ listen: etckeeper_commit_conf
diff --git a/roles/etckeeper/tasks/main.yml b/roles/etckeeper/tasks/main.yml
index 6752f92..431a378 100644
--- a/roles/etckeeper/tasks/main.yml
+++ b/roles/etckeeper/tasks/main.yml
@@ -46,6 +46,7 @@
value: '1'
- name: AVOID_COMMIT_BEFORE_INSTALL
value: '1'
+ notify: etckeeper_commit_conf
- name: Configure repository remote
when: etckeeper_remote_url is defined
@@ -72,3 +73,4 @@
section: null
option: PUSH_REMOTE
value: '{{ etckeeper_remote_name }}'
+ notify: etckeeper_commit_conf