需先装 Xcode 命令行工具,否则 Homebrew 相关步骤会失败;运行前要先执行 ansible-galaxy install 拉取依赖角色;部分 App Store 应用和专有软件在虚拟机中可能装不上
xcode-select --install
pip3 install ansible
ansible-galaxy install -r requirements.yml
ansible-playbook main.yml --ask-become-passREADME 未说明;需在 macOS 上运行,也可通过 SSH 管理远程 Mac,控制端不必是 Mac
用 Ansible 一键装好 Mac 开发环境,省去手动装软件和调系统设置
用 Ansible 一键配置 macOS 开发环境,自动安装 Homebrew 软件、dotfiles 和系统偏好设置,省去换机或重装后手动折腾的时间。
核心能力
- 用 Homebrew 和 Cask 批量安装命令行工具与图形应用
- 用 mas 按 App Store ID 自动安装商店应用
- 安装 dotfiles 并用 .osx 配置 macOS 系统偏好
- 支持 --tags 只跑 dotfiles、homebrew、mas 等指定部分
- 用 config.yml 覆盖默认软件包与 Dock 配置
容易踩的坑
暂无 release 数据(可能没有发版,或尚未同步)。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Mac Development Ansible Playbook
This playbook installs and configures most of the software I use on my Mac for web and software development. Some things in macOS are slightly difficult to automate, so I still have a few manual installation steps, but at least it's all documented here.
Installation
-
Ensure Apple's command line tools are installed (
xcode-select --installto launch the installer). -
- Run the following command to add Python 3 to your $PATH:
export PATH="$HOME/Library/Python/3.9/bin:/opt/homebrew/bin:$PATH" - Upgrade Pip:
sudo pip3 install --upgrade pip - Install Ansible:
pip3 install ansible
- Run the following command to add Python 3 to your $PATH:
-
Clone or download this repository to your local drive.
-
Run
ansible-galaxy install -r requirements.ymlinside this directory to install required Ansible roles. -
Run
ansible-playbook main.yml --ask-become-passinside this directory. Enter your macOS account password when prompted for the 'BECOME' password.
Note: If some Homebrew commands fail, you might need to agree to Xcode's license or fix some other Brew issue. Run
brew doctorto see if this is the case.
Use with a remote Mac
You can use this playbook to manage other Macs as well; the playbook doesn't even need to be run from a Mac at all! If you want to manage a remote Mac, either another Mac on your network, or a hosted Mac like the ones from MacStadium, you just need to make sure you can connect to it with SSH:
- (On the Mac you want to connect to:) Go to System Settings > Sharing.
- Enable 'Remote Login'.
You can also enable remote login on the command line:
sudo systemsetup -setremotelogin on
Then edit the inventory file in this repository and change the line that starts with 127.0.0.1 to:
[ip address or hostname of mac] ansible_user=[mac ssh username]
If you need to supply an SSH password (if you don't use SSH keys), make sure to pass the --ask-pass parameter to the ansible-playbook command.
Running a specific set of tagged tasks
You can filter which part of the provisioning process to run by specifying a set of tags using ansible-playbook's --tags flag. The tags available are dotfiles, homebrew, mas, extra-packages and osx.
ansible-playbook main.yml -K --tags "dotfiles,homebrew"
Overriding Defaults
Not everyone's development environment and preferred software configuration is the same.
You can override any of the defaults configured in default.config.yml by creating a config.yml file and setting the overrides in that file. For example, you can customize the installed packages and apps with something like:
homebrew_installed_packages:
- git
- go
mas_installed_apps:
- { id: 443987910, name: "1Password" }
- { id: 498486288, name: "Quick Resizer" }
- { id: 557168941, name: "Tweetbot" }
- { id: 497799835, name: "Xcode" }
composer_packages:
- name: hirak/prestissimo
- name: drush/drush
version: '^8.1'
gem_packages:
- name: bundler
state: latest
npm_packages:
- name: webpack
pip_packages:
- name: mkdocs
configure_dock: true
dockitems_remove:
- Launchpad
- TV
dockitems_persist:
- name: "Sublime Text"
path: "/Applications/Sublime Text.app/"
pos: 5
Any variable can be overridden in config.yml; see the supporting roles' documentation for a complete list of available variables.
Included Applications / Configuration (Default)
Applications (installed with Homebrew Cask):
- ChromeDriver
- Docker
- Dropbox
- Firefox
- Google Chrome
- Handbrake
- Homebrew
- LICEcap
- nvALT
- Sequel Ace (MySQL client)
- Slack
- Sublime Text
- Transmit (S/FTP client)
Packages (installed with Homebrew):
- autoconf
- bash-completion
- doxygen
- gettext
- gifsicle
- git
- gh
- go
- gpg
- httpie
- iperf
- libevent
- sqlite
- nmap
- node
- nvm
- php
- ssh-copy-id
- readline
- openssl
- pv
- wget
- wrk
- zsh-history-substring-search
My dotfiles are also installed into the current user's home directory, including the .osx dotfile for configuring many aspects of macOS for better performance and ease of use. You can disable dotfiles management by setting configure_dotfiles: no in your configuration.
Finally, there are a few other preferences and settings added on for various apps and services.
Full / From-scratch setup guide
Since I've used this playbook to set up something like 20 different Macs, I decided to write up a full 100% from-scratch install for my own reference (everyone's particular install will be slightly different).
You can see my full from-scratch setup document here: full-mac-setup.md.
Testing the Playbook
Many people have asked me if I often wipe my entire workstation and start from scratch just to test changes to the playbook. Nope! This project is continuously tested on GitHub Actions' macOS infrastructure.
You can also run macOS itself inside a VM, for at least some of the required testing (App Store apps and some proprietary software might not install properly). I currently recommend:
Ansible for DevOps
Check out Ansible for DevOps, which teaches you how to automate almost anything with Ansible.
Author
This project was created by Jeff Geerling (originally inspired by MWGriffin/ansible-playbooks).