Add role etckeeper

This commit is contained in:
flyingscorpio@clevo 2022-03-10 23:14:44 +01:00
parent 5e509284b1
commit 66451e3287
5 changed files with 53 additions and 12 deletions

View file

@ -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"

View file

@ -31,3 +31,4 @@
- { role: rsync-backup, tags: rsync-backup }
- { role: gitea-backup, tags: gitea-backup }
- { role: gaming, tags: gaming }
- { role: etckeeper, tags: etckeeper }

View file

@ -0,0 +1,3 @@
---
dependencies:
- role: check-sudo

View file

@ -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"

View file

@ -0,0 +1,5 @@
[user]
name = root@{{ ansible_hostname }}
email = root@{{ ansible_hostname }}
[init]
defaultBranch = main