summaryrefslogtreecommitdiffstats
path: root/roles/yay/tasks/main.yml
blob: 59af378cbc3a8c68ee4f4ac3007098ae17a373a4 (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
---
- name: "Ensure base-devel is installed"
  become: true
  ansible.builtin.package:
    name: "base-devel"
    state: "present"

- name: "Check if yay exists"
  ansible.builtin.stat:
    path: "/usr/bin/yay"
  register: yay_binary

- name: "Install yay"
  when: not yay_binary.stat.exists
  block:
    - name: "Clone yay-bin"
      ansible.builtin.git:
        repo: "https://aur.archlinux.org/yay-bin.git"
        dest: "/tmp/yay-bin"
        clone: true
        update: false
        single_branch: true
        version: "master"

    - name: "Build yay-bin"
      ansible.builtin.command:
        cmd: "makepkg --syncdeps --noconfirm"
        chdir: "/tmp/yay-bin"
      args:
        creates: "/tmp/yay-bin/yay-bin-*.pkg.tar.zst"

    - name: "Install yay bin"
      become: true
      ansible.builtin.shell:
        cmd: "pacman -U --noconfirm /tmp/yay-bin/yay-bin-*.pkg.tar.zst"
      args:
        creates: "/usr/bin/yay"

- name: "Configure yay aur_builder passwordless"
  # yay builder is the user that is allowed to execute yay wihtout password
  # to be able to use yay automation or archlinux
  # Ref: https://github.com/kewlfft/ansible-aur?tab=readme-ov-file#usage
  block:
    - name: "Create the 'aur_builder' user"
      become: true
      ansible.builtin.user:
        name: "aur_builder"
        create_home: true
        group: wheel

    - name: "Allow 'username' to become 'aur_builder' user without a password"
      become: true
      ansible.builtin.lineinfile:
        path: "/etc/sudoers.d/10-aur_builder-become"
        line: "{{ username }} ALL=(aur_builder) NOPASSWD: ALL"
        create: true
        mode: "0644"
        validate: "visudo -cf %s"

    - name: "Allow the 'aur_builder' user to run 'sudo pacman' without a password"
      become: true
      ansible.builtin.lineinfile:
        path: "/etc/sudoers.d/11-aur_builder-pacman"
        line: "aur_builder ALL=(ALL) NOPASSWD: /usr/bin/pacman"
        create: true
        mode: "0644"
        validate: "visudo -cf %s"