Ansible Modules homebrew and homebrew cask: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=External= =Internal= =Overview=")
 
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
=External=
* https://docs.ansible.com/ansible/latest/collections/community/general/homebrew_module.html
* https://docs.ansible.com/ansible/2.5/modules/homebrew_module.html
* https://docs.ansible.com/ansible/latest/collections/community/general/homebrew_cask_module.html
=Internal=
=Internal=
* [[Ansible_Concepts#homebrew|Ansible Concepts | Modules by Category]]
=Overview=
=Overview=
Install a Homebrew [[Brew_Concepts#Formula|formula]] or [[Brew_Concepts#Cask|cask]]. Also see: {{Internal|Brew_Operations#install|brew install}}
To install a formula:
<syntaxhighlight lang='yaml'>
- name: Install bash
  homebrew:
    name: bash
  register: brew_install_result
</syntaxhighlight>
To install a cask:
<syntaxhighlight lang='yaml'>
- name: Install Corretto 11
  homebrew_cask:
    name: corretto11
  register: brew_install_result
</syntaxhighlight>
In both cases, <code>brew_install_result</code> is initialized to something similar to:
<syntaxhighlight lang='json'>
{
  "changed": false,
  "failed": false,
  "msg": "Cask already installed: corretto11"
}
</syntaxhighlight>
The variable can be used to detect whether the installation changed something on the filesystem or not:
<syntaxhighlight lang='yaml'>
- name: Setting Update Fact
  set_fact:
    brew_formula_or_cask_installed_or_updated: "{{ brew_install_result.changed | bool}}"
- name: "info"
  when: brew_formula_or_cask_installed_or_updated
  debug:
    msg: "Formula/Cask Was Installed or Updated"
- name: "info"
  when: not brew_formula_or_cask_installed_or_updated
  debug:
    msg: "Formula/Cask Was NOT Modified"
</syntaxhighlight>
=Parameters=
==<tt>state</tt>==
A string describing the <font color=darkgray>state of the formula or cask</font>. Possible values are:
* "absent"
* "installed"
* "latest"
* "present"
* "removed"
* "uninstalled"
* "upgraded"
The default value is "present"

Latest revision as of 19:31, 5 July 2021

External

Internal

Overview

Install a Homebrew formula or cask. Also see:

brew install

To install a formula:

- name: Install bash
  homebrew:
    name: bash
  register: brew_install_result

To install a cask:

- name: Install Corretto 11
  homebrew_cask:
    name: corretto11
  register: brew_install_result

In both cases, brew_install_result is initialized to something similar to:

{
  "changed": false,
  "failed": false,
  "msg": "Cask already installed: corretto11"
}

The variable can be used to detect whether the installation changed something on the filesystem or not:

- name: Setting Update Fact
  set_fact:
    brew_formula_or_cask_installed_or_updated: "{{ brew_install_result.changed | bool}}"
- name: "info"
  when: brew_formula_or_cask_installed_or_updated
  debug:
    msg: "Formula/Cask Was Installed or Updated"
- name: "info"
  when: not brew_formula_or_cask_installed_or_updated
  debug:
    msg: "Formula/Cask Was NOT Modified"

Parameters

state

A string describing the state of the formula or cask. Possible values are:

  • "absent"
  • "installed"
  • "latest"
  • "present"
  • "removed"
  • "uninstalled"
  • "upgraded"

The default value is "present"