From ac373d3479ffcca00890faa24d42dec5d6e0b279 Mon Sep 17 00:00:00 2001 From: Scott Wallace Date: Thu, 12 Oct 2017 22:28:35 +0100 Subject: [PATCH] Replace software-install scripts with Ansible playbook and role. --- .Brewfile | 41 ------- .ansible.cfg | 2 + .ansible/inventory.yaml | 4 + .../roles/mac_desktop/tasks/homebrew.yaml | 39 +++++++ .ansible/roles/mac_desktop/tasks/main.yaml | 4 + .ansible/roles/mac_desktop/tasks/mas.yaml | 2 + .ansible/roles/mac_desktop/tasks/prefs.yaml | 2 + .ansible/roles/mac_desktop/vars/main.yaml | 50 +++++++++ .ansible/site.yaml | 4 + bin/software-install | 103 ------------------ 10 files changed, 107 insertions(+), 144 deletions(-) delete mode 100644 .Brewfile create mode 100644 .ansible.cfg create mode 100644 .ansible/inventory.yaml create mode 100644 .ansible/roles/mac_desktop/tasks/homebrew.yaml create mode 100644 .ansible/roles/mac_desktop/tasks/main.yaml create mode 100644 .ansible/roles/mac_desktop/tasks/mas.yaml create mode 100644 .ansible/roles/mac_desktop/tasks/prefs.yaml create mode 100644 .ansible/roles/mac_desktop/vars/main.yaml create mode 100644 .ansible/site.yaml delete mode 100755 bin/software-install diff --git a/.Brewfile b/.Brewfile deleted file mode 100644 index c0d5a22..0000000 --- a/.Brewfile +++ /dev/null @@ -1,41 +0,0 @@ -tap "caskroom/versions" -tap "buo/homebrew-cask-upgrade" - -brew "ack" -brew "bash-completion" -brew "git" -brew "coreutils" -brew "htop-osx" -brew "ipcalc" -brew "mosh" -brew "nmap" -brew "p7zip" -brew "psgrep" -brew "pv" -brew "python3" -brew "rename" -brew "task" -brew "tree" -brew "vim" - -cask "alfred" -cask "bbc-iplayer-downloads" -cask "beardedspice" -cask "cleanmymac" -cask "enpass" -cask "firefox" -cask "google-backup-and-sync" -cask "google-chrome" -cask "google-hangouts" -cask "handbrake" -cask "iterm2" -cask "itsycal" -cask "osxfuse" -cask "resilio-sync" -cask "sonos" -cask "sublime-text" -cask "virtualbox" -cask "wireshark" -cask "xquartz" -cask "yubikey-manager" -cask "yubikey-personalization-gui" diff --git a/.ansible.cfg b/.ansible.cfg new file mode 100644 index 0000000..c650cff --- /dev/null +++ b/.ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +inventory = ~/.ansible/inventory.yaml diff --git a/.ansible/inventory.yaml b/.ansible/inventory.yaml new file mode 100644 index 0000000..dbf736c --- /dev/null +++ b/.ansible/inventory.yaml @@ -0,0 +1,4 @@ +mac_desktops: + hosts: + localhost: + ansible_connection: local diff --git a/.ansible/roles/mac_desktop/tasks/homebrew.yaml b/.ansible/roles/mac_desktop/tasks/homebrew.yaml new file mode 100644 index 0000000..bbf3d3b --- /dev/null +++ b/.ansible/roles/mac_desktop/tasks/homebrew.yaml @@ -0,0 +1,39 @@ +# Install Homebrew +- name: Check for Homebrew + stat: + path: /usr/local/bin/brew + register: st + +- name: Install Homebrew + command: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + when: st.stat.executable != True + +- name: Disable Homebrew analytics + command: brew analytics off + +# Taps +- name: Install Homebrew Taps + homebrew_tap: + name: "{{ item }}" + state: present + with_items: "{{ homebrew_tap_items }}" + +# Update and upgrades +- name: Homebrew update and upgrades + homebrew: + update_homebrew: True + upgrade_all: True + +# Brews +- name: Install Homebrew Brews + homebrew: + name: "{{ item }}" + state: present + with_items: "{{ homebrew_brew_items }}" + +# Casks +- name: Install Homebrew Casks + homebrew_cask: + name: "{{ item }}" + state: present + with_items: "{{ homebrew_cask_items }}" diff --git a/.ansible/roles/mac_desktop/tasks/main.yaml b/.ansible/roles/mac_desktop/tasks/main.yaml new file mode 100644 index 0000000..eb3c441 --- /dev/null +++ b/.ansible/roles/mac_desktop/tasks/main.yaml @@ -0,0 +1,4 @@ +- name: Homebrew tasks + import_tasks: homebrew.yaml +- import_tasks: mas.yaml +- import_tasks: prefs.yaml diff --git a/.ansible/roles/mac_desktop/tasks/mas.yaml b/.ansible/roles/mac_desktop/tasks/mas.yaml new file mode 100644 index 0000000..de29e58 --- /dev/null +++ b/.ansible/roles/mac_desktop/tasks/mas.yaml @@ -0,0 +1,2 @@ +- name: Upgrade AppStore apps + command: mas upgrade diff --git a/.ansible/roles/mac_desktop/tasks/prefs.yaml b/.ansible/roles/mac_desktop/tasks/prefs.yaml new file mode 100644 index 0000000..67c5f08 --- /dev/null +++ b/.ansible/roles/mac_desktop/tasks/prefs.yaml @@ -0,0 +1,2 @@ +- name: Clear preferences cache + command: pkill -u ${USER} cfprefsd diff --git a/.ansible/roles/mac_desktop/vars/main.yaml b/.ansible/roles/mac_desktop/vars/main.yaml new file mode 100644 index 0000000..1cbc945 --- /dev/null +++ b/.ansible/roles/mac_desktop/vars/main.yaml @@ -0,0 +1,50 @@ +homebrew_tap_items: + - caskroom/versions + - buo/homebrew-cask-upgrade + +homebrew_brew_items: + - ack + - bash-completion + - curl + - git + - coreutils + - htop-osx + - ipcalc + - mas + - mosh + - nmap + - p7zip + - psgrep + - pv + - python3 + - rename + - screen + - task + - tree + - vim + - watch + +homebrew_cask_items: + - alfred + - bbc-iplayer-downloads + - beardedspice + - cleanmymac + - enpass + - firefox + - flux + - google-backup-and-sync + - google-chrome + - google-hangouts + - handbrake + - iterm2 + - itsycal + - osxfuse + - resilio-sync + - sonos + - sublime-text + - virtualbox + - whatsapp + - wireshark + - xquartz + - yubikey-manager + - yubikey-personalization-gui diff --git a/.ansible/site.yaml b/.ansible/site.yaml new file mode 100644 index 0000000..d6273fb --- /dev/null +++ b/.ansible/site.yaml @@ -0,0 +1,4 @@ +- name: Mac desktops + hosts: mac_desktops + roles: + - mac_desktop diff --git a/bin/software-install b/bin/software-install deleted file mode 100755 index 2f7b83e..0000000 --- a/bin/software-install +++ /dev/null @@ -1,103 +0,0 @@ -#!/bin/bash - -function configure_Linux_software { - echo "Not configured yet." -} - -function configure_Darwin_software { - # Ensure any preference cache is cleared - pkill -u ${USER} cfprefsd -} - -function install_Linux_software { - #------------------------------- - # Check the OS and set install command - #------------------------------- - if [ -x "$(which yum)" ]; then - INSTALLCMD="yum install -y" - elif [ -x "$(which apt-get)" ]; then - INSTALLCMD="apt-get install -y" - else - echo "Sorry, I don't know how to install software on this OS yet." - exit 1 - fi - #------------------------------- - - xargs -n1 sudo ${INSTALLCMD} <<-EOF - ack - archey - bash-completion - git - htop - mosh - nmap - p7zip - psgrep - pv - ss - vim - EOF -} - -function install_Darwin_software { - #------------------------------- - # Install Homebrew if missing - #------------------------------- - if [ ! -x /usr/local/bin/brew ]; then - ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - brew tap buo/cask-upgrade - fi - #------------------------------- - - # Disable Homebrew's Google Analytics tracking - brew analytics off - - # Update Brew formulae if older than 24 hours - find /usr/local/Homebrew/.git -name FETCH_HEAD -mtime +0 -exec brew update \; - - # Install homebrew/bundle tap if we don't have it - [ -d /usr/local/Library/Taps/homebrew/homebrew-bundle ] || brew tap homebrew/bundle - - #------------------------------- - # Run brew bundle if there's a newer version of Brewfile - #------------------------------- - if [ ~/.Brewfile -nt ~/.Brewfile.updated ]; then - ( brew bundle --global install && touch ~/.Brewfile.updated ) - fi - #------------------------------- - - #------------------------------- - # Upgrade and clean Brew - #------------------------------- - brew upgrade - brew cleanup - brew bundle --global check - brew cask cleanup - brew cu -y --cleanup - #------------------------------- - - #------------------------------- - # OS X software update - #------------------------------- - softwareupdate -ia --verbose - #------------------------------- -} - -function install_python_modules { - pip install pyopenssl -} - -echo "#-------------------------------" -echo "# START: $(date)" -echo "#-------------------------------" - -# Call the install function appropriate for this platform -install_$(uname -s)_software -configure_$(uname -s)_software -install_python_modules - -echo "#-------------------------------" -echo "# END: $(date)" -echo "#-------------------------------" - -exit 0