aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roles/etckeeper/tasks/main.yml
blob: c426c055c14d3862532b4bbfb741959d4ad45f72 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
- name: Install etckeeper
  become: true
  ansible.builtin.package:
    name: etckeeper
    state: present

- name: etckeeper init
  become: true
  ansible.builtin.command: etckeeper init
  args:
    creates: /etc/.git/config

- name: Configure /etc repository
  become: true
  community.general.git_config:
    scope: local
    repo: /etc
    name: '{{ item.name }}'
    value: '{{ item.value }}'
  loop:
    - name: user.name
      value: '{{ etckeeper_git_name }}'
    - name: user.email
      value: '{{ etckeeper_git_email }}'

- name: Initial commit
  become: true
  ansible.builtin.command: etckeeper commit 'initial commit'
  args:
    creates: /etc/.git/index

- name: Configure etckeeper
  become: true
  community.general.ini_file:
    path: /etc/etckeeper/etckeeper.conf
    # I'm pretty sure this file is sourced by a shell, so this is required:
    no_extra_spaces: true
    owner: root
    group: root
    mode: '644'
    section: null
    option: '{{ item.name }}'
    value: '{{ item.value }}'
  loop:
    - name: AVOID_DAILY_AUTOCOMMITS
      value: '1'
    - name: AVOID_COMMIT_BEFORE_INSTALL
      value: '1'
  notify: etckeeper_commit_conf

- name: Configure repository remote
  when: etckeeper_remote_url is defined
  become: true
  block:
    - name: git remote add
      ansible.builtin.command:
        argv:
          - git
          - remote
          - add
          - '{{ etckeeper_remote_name }}'
          - '{{ etckeeper_remote_url }}'
        chdir: /etc
        creates: '/etc/.git/refs/remotes/{{ etckeeper_remote_name }}/'

    - name: Configure pushes for etckeeper
      community.general.ini_file:
        path: /etc/etckeeper/etckeeper.conf
        no_extra_spaces: true
        owner: root
        group: root
        mode: '644'
        section: null
        option: PUSH_REMOTE
        value: '{{ etckeeper_remote_name }}'
      notify: etckeeper_commit_conf

- name: Commit etckeeper.conf if necessary
  ansible.builtin.meta: flush_handlers

- name: Configure ignored paths
  ansible.builtin.include_tasks: ignore.yml
  loop: '{{ etckeeper_ignored_paths + etckeeper_extra_ignored_paths }}'
  loop_control:
    loop_var: ignore_path

- name: Commit .gitignore if necessary
  ansible.builtin.meta: flush_handlers