From 66451e32878c79a056db7df0eec631e4a064bac0 Mon Sep 17 00:00:00 2001 From: "flyingscorpio@clevo" Date: Thu, 10 Mar 2022 23:14:44 +0100 Subject: [PATCH] Add role etckeeper --- configs.yml | 12 ------- playbook.yml | 1 + roles/etckeeper/meta/main.yml | 3 ++ roles/etckeeper/tasks/main.yml | 44 ++++++++++++++++++++++++++ roles/etckeeper/templates/gitconfig.j2 | 5 +++ 5 files changed, 53 insertions(+), 12 deletions(-) delete mode 100644 configs.yml create mode 100644 roles/etckeeper/meta/main.yml create mode 100644 roles/etckeeper/tasks/main.yml create mode 100644 roles/etckeeper/templates/gitconfig.j2 diff --git a/configs.yml b/configs.yml deleted file mode 100644 index 32652e3..0000000 --- a/configs.yml +++ /dev/null @@ -1,12 +0,0 @@ -etckeeper: - - install: - - etckeeper - - run: - - sudo git config --global user.name "root@$(uname -n)"; - sudo git config --global user.email "root@$(uname -n)"; - sudo git config --global init.defaultBranch "main" - - run: - command: sudo etckeeper init - condition: "[ ! -d /etc/.git ]" - - run: - - sudo etckeeper commit "First commit" diff --git a/playbook.yml b/playbook.yml index 0025fb0..04f301a 100644 --- a/playbook.yml +++ b/playbook.yml @@ -31,3 +31,4 @@ - { role: rsync-backup, tags: rsync-backup } - { role: gitea-backup, tags: gitea-backup } - { role: gaming, tags: gaming } + - { role: etckeeper, tags: etckeeper } diff --git a/roles/etckeeper/meta/main.yml b/roles/etckeeper/meta/main.yml new file mode 100644 index 0000000..edef5f0 --- /dev/null +++ b/roles/etckeeper/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - role: check-sudo diff --git a/roles/etckeeper/tasks/main.yml b/roles/etckeeper/tasks/main.yml new file mode 100644 index 0000000..48fd455 --- /dev/null +++ b/roles/etckeeper/tasks/main.yml @@ -0,0 +1,44 @@ +--- +- name: Install etckeeper (Archlinux) + become: true + pacman: + name: + - etckeeper + when: ansible_facts['distribution'] == 'Archlinux' + +- name: Install etckeeper (Debian) + become: true + apt: + name: + - etckeeper + when: ansible_facts['distribution'] == 'Debian' + +- name: Copy gitconfig for root + become: true + template: + src: gitconfig.j2 + dest: /root/.gitconfig + backup: true + +- name: Check if etckeeper is initialized + stat: + path: /etc/.git + register: etckeeper_git + +- name: Initialize etckeeper + become: true + command: etckeeper init + when: not etckeeper_git.stat.exists + +- name: Check if first commit exists + become: true + command: + cmd: git status + chdir: /etc + register: git_status + changed_when: false + +- name: Make first commit + become: true + command: etckeeper commit 'First commit' + when: "'No commits yet' in git_status.stdout" diff --git a/roles/etckeeper/templates/gitconfig.j2 b/roles/etckeeper/templates/gitconfig.j2 new file mode 100644 index 0000000..9552c54 --- /dev/null +++ b/roles/etckeeper/templates/gitconfig.j2 @@ -0,0 +1,5 @@ +[user] + name = root@{{ ansible_hostname }} + email = root@{{ ansible_hostname }} +[init] + defaultBranch = main