aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roles/config_links/tasks/main.yml
blob: c014040f6154915ccfcf3256d0c2aab473e44fdd (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
- name: Fail if invalid action
  when: |
    config_links_action not in ['update', 'remove']
  ansible.builtin.fail:
    msg: |
      Action parameter must be either 'update' or 'remove'

- name: Create temporary directory
  ansible.builtin.tempfile:
    prefix: config-links
    state: directory
  register: config_links_repo

- name: Run config-links
  block:
    - name: Checkout config-links repo
      # noqa: latest[git]
      # config-links is supposed to be always working if you just check it out.
      ansible.builtin.git:
        repo: 'https://github.com/egor-tensin/config-links.git'
        dest: '{{ config_links_repo.path }}'
        accept_hostkey: true

    - name: Run links-update
      when: config_links_action == 'update'
      ansible.builtin.command:
        cmd: '{{ config_links_repo.path }}/links-update'
        chdir: '{{ config_links_path }}'
      changed_when: true

    - name: Run links-remove
      when: config_links_action == 'remove'
      ansible.builtin.command:
        cmd: '{{ config_links_repo.path }}/links-remove'
        chdir: '{{ config_links_path }}'
      changed_when: true

  always:
    - name: Clean up
      ansible.builtin.file:
        path: '{{ config_links_repo.path }}'
        state: absent