0
votes

I can gather a list of Ansible facts on my MacOS system locally, using the following command:

ansible -m setup localhost

However, this list of facts doesn't provide a list of Homebrew packages that are installed, apparently.

If I run this command, I don't get any extra information about installed Homebrew packages either:

ansible -m homebrew localhost

All I get is the following output:

localhost | SUCCESS => {
    "changed": false,
    "msg": ""
}

Question: How can I extend Ansible to gather a list of installed Homebrew packages as Ansible "facts"?

1

1 Answers

0
votes

To solve this, I just learned how to create Ansible custom facts via this article.

The solution is painfully simple. I created the following custom Ansible fact file under the path /etc/ansible/facts.d/homebrew.fact, which worked flawlessly.

#!/usr/bin/env pwsh
brew list -1 | ConvertTo-Json

Make sure that you make the *.fact* files executable as well, otherwise they won't be called by Ansible.

sudo chmod +x /etc/ansible/facts.d/homebrew.fact

NOTE: Requires PowerShell to be installed. brew cask install powershell