summaryrefslogtreecommitdiffstats
path: root/roles/homebrew/tasks/main.yml
blob: 9d3f1701ad5b0f90cce171db29994c07eef1549b (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
---
- name: "Check if homebrew is already installed"
  ansible.builtin.stat:
    path: "/home/linuxbrew/.linuxbrew/bin/brew"
  register: homebrew_binary_check

- name: "Install homebrew"
  when: not homebrew_binary_check.stat.exists
  block:
    - name: "Create linuxbrew directory"
      become: true
      ansible.builtin.file:
        path: "/home/linuxbrew"
        state: directory
        owner: "{{ ansible_user_id }}"
        group: "{{ ansible_user_id }}"
        mode: "0755"

    - name: "Download homebrew installer"
      ansible.builtin.get_url:
        url: "https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
        dest: "/tmp/install_homebrew.sh"
        mode: "0755"

    - name: "Run homebrew installer"
      ansible.builtin.command:
        cmd: "/tmp/install_homebrew.sh"
      args:
        creates: "/home/linuxbrew/.linuxbrew/bin/brew"
      environment:
        NONINTERACTIVE: "1"

- name: "Add homebrew to shell profile"
  ansible.builtin.blockinfile:
    path: "{{ ansible_env.HOME }}/.bashrc"
    state: "present"
    prepend_newline: true
    append_newline: true
    marker: "# ==== {mark} ANSIBLE HOMEBREW CONFIG"
    create: true
    mode: "0644"
    block: |
      eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"