--- - 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)"