diff options
| author | Ahmed Abdelhalim <[email protected]> | 2025-09-01 21:26:21 +0200 |
|---|---|---|
| committer | Ahmed Abdelhalim <[email protected]> | 2025-09-01 21:26:21 +0200 |
| commit | 38b83b874e91027449e2ffcc2f8ee9e50d4c6554 (patch) | |
| tree | 930b11976964a4fd7beced4d3fac6c784ff462c2 | |
| parent | 3539ae655847b89858d232f78b82cc6cd4924426 (diff) | |
Update homebrew role to avoid unnecessary downloads
| -rw-r--r-- | roles/homebrew/tasks/main.yml | 82 |
1 files changed, 45 insertions, 37 deletions
diff --git a/roles/homebrew/tasks/main.yml b/roles/homebrew/tasks/main.yml index 66632534..7dc273be 100644 --- a/roles/homebrew/tasks/main.yml +++ b/roles/homebrew/tasks/main.yml @@ -2,44 +2,52 @@ - name: "Include OS-specific variables" ansible.builtin.include_vars: "{{ ansible_os_family | lower }}.yml" -- name: "Install homebrew dependencies" - become: true - ansible.builtin.package: - name: "{{ item }}" - state: "present" - with_items: "{{ homebrew_dependencies }}" +- name: "Check if homebrew is already installed" + ansible.builtin.stat: + path: "/home/linuxbrew/.linuxbrew/bin/brew" + register: homebrew_binary_check -- 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: "Install homebrew" + when: not homebrew_binary_check.stat.exists + block: + - name: "Install homebrew dependencies" + become: true + ansible.builtin.package: + name: "{{ item }}" + state: "present" + with_items: "{{ homebrew_dependencies }}" -- 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: "Create linuxbrew directory" + become: true + ansible.builtin.file: + path: "/home/linuxbrew" + state: directory + owner: "{{ ansible_user_id }}" + group: "{{ ansible_user_id }}" + 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: "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: "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)" + - 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)" |
