I'm a relatively new user of Ansible. I use it to orchestrate a few groups of Linux servers. I'm now expanding that use to use Ansible's homebrew module.

Using the homebrew module, I want to assert that a list of packages are installed on my macOS boxes. So far, the best I can do is to make separate roles for each package, with each role resembling:

- name: "htop"
    name: htop
    state: present

It seems like there must be a way to give a list of packages in a single role, which I've seen before when using the Ansible apt module.

Any tips? Does the homebrew module itself expressly have to support for this sort of operation or perhaps there's something more fundamental to Ansible or even Python itself that provides what I'm looking for?

PS - You can safely assume that my macOS machines are all servers.

1 Answer 1


I've found a solution, more or less. My role now looks like this, and it works:

- name: "brew favourites"
  homebrew: name={{ item }} state=present
    - htop
    - nmap
    - telnet
    - wget
    - nginx

Extended Notes

I don't really know what mechanism is responsible for this working. I feel like it's outside of Ansible and is actually a Pythonism (Is this a Lamda?). Whatever it is, it could serve as a template for a general solution to this sort of thing.

I tried the above after seeing something similar described for defining a list of apt packages, that approach looks like:

- name: "Asserting apt packages"
  apt: pkg={{ item }} state=installed
    - aptitude
    - vim
    - htop
    - nmap
    - curl
    - screen
    - open-vm-tools

Thus note that in the apt module, I wanted to have many packages listed for the pkg parameter. In the homebrew modules' context, it wasn't pkg, but instead name.

Similarly, both Ansible modules have a state parameter, but for apt the appropriate value was installed, and with homebrew it's present.

So I think this sort of syntax applies to Ansible in a global context. And modules need have zero awareness or explicit support of this. Powerful.

  • 2
    No idea why someone down voted both the q/a. There's nothing wrong with self answer. It's even encouraged.
    – jscott
    Oct 26, 2017 at 12:38
  • Therefore, +1 ..
    – gxx
    Oct 26, 2017 at 12:53
  • @jscott - I wager the downvote was because at that point I didn't have my "PS - these are servers comment". If an Ansible question belongs anywhere, one would think serverfault would be it. Oct 26, 2017 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.