ansibleversioninghomebrew-cask

How to install specific version of brew cask formula with ansible?


How do I install a specific version of a homebrew cask formula with ansible? For example, vagrant 2.2.6 whereas latest available is 2.2.7.


Solution

  • I have found this solution:

    ---
    - hosts: all
      tasks:
      - name: Task 1 - Check vagrant 2.2.6 is installed
        stat: path=/usr/local/Caskroom/vagrant/2.2.6
        register: vagrant_installed
      - name: Task 2 - Install vagrant 2.2.6 if not yet installed
        block:
          - name: Create temporary directory to download vagrant formula
            tempfile:
              state: directory
            register: tempdir_vagrant_rb
          - name: Download formula vagrant.rb version 2.2.6
            get_url:
              url: https://raw.githubusercontent.com/Homebrew/homebrew-cask/ae2a540ffee555491ccbb2cefa4296c76355ef9f/Casks/vagrant.rb
              dest: "{{ tempdir_vagrant_rb.path }}/vagrant.rb"
          - name: Install vagrant 2.2.6
            command: brew cask install {{ tempdir_vagrant_rb.path }}/vagrant.rb
    

    First task checks if vagrant 2.2.6 is already installed by going to default cask directory. It's required to keep playbook idempotent.

    Second task installs vagrant 2.2.6 using direct raw URL to the formula version 2.2.6. To find the URL, I have used this step-by-step documentation.