DEV Community

Katsuhisa Kitano
Katsuhisa Kitano

Posted on

My Ansible Playbook for setup M1 Mac

The other day, I bought an M1 Mac. The setup seemed to be a pain, so I made an Ansible Playbook so that I can easily recreate it later.

GitHub

https://github.com/katsuhisa91/m1mac-ansible

About Roles

roles about
prezto Prezto is the configuration framework for Zsh. https://github.com/sorin-ionescu/prezto
dotfiles This is my dot files. https://github.com/katsuhisa91/dotfiles
rustup Install Rust by rustup for my favorite command. https://github.com/rust-lang/rustup/blob/master/doc/src/installation/index.md#installing-nightly
command This is my favorite command.

How to execute

1. Install xcode command line tools

xcode-select --install
Enter fullscreen mode Exit fullscreen mode

2. Install Homebrew

Follow the steps below and you should be able to install it without any problems.

https://docs.brew.sh/Installation

This script installs Homebrew to its preferred prefix (/usr/local for macOS Intel, /opt/homebrew for Apple Silicon) so that you don’t need sudo when you brew install.

cd /opt
sudo mkdir homebrew
sudo chown $USER homebrew
sudo chgrp admin homebrew
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
Enter fullscreen mode Exit fullscreen mode

3. Set PATH for M1 Mac brew

export PATH="/opt/homebrew/bin:$PATH"
Enter fullscreen mode Exit fullscreen mode

4. brew install Ansible

brew install ansible
Enter fullscreen mode Exit fullscreen mode

5. Setup & Execute Playbook

#!/bin/zsh

ANSIBLE_PATH=~/workspace/settings/m1mac-ansible

## clone repo
git clone https://github.com/katsuhisa91/m1mac-ansible.git ${ANSIBLE_PATH}

## ansible galaxy
ansible-galaxy collection install community.general

## ansible
cd ${ANSIBLE_PATH}
ansible-playbook -i inventory/localhost localhost.yml
Enter fullscreen mode Exit fullscreen mode

That's it! Enjoy your M1 Mac life! πŸš€

Top comments (1)

Collapse
 
ian_strathdee_e593f4a639f profile image
Ian Strathdee

This did not work for me. I didn't check the playbook but I got errors during "backup zsh dot files" (pretty important I would think to fail the script before it continues past) and "Run setup targets".

Errors are:

1 - TASK [prezto : Backup zsh dot files] ********************************************************************************************************

changed: [127.0.0.1] => (item=.zshrc)
failed: 127.0.0.1 => {"ansible_loop_var": "item", "changed": true, "cmd": ["cp", "-rp", "~/.zlogin", "~/zsh_original/"], "delta": "0:00:00.004094", "end": "2021-11-09 22:13:30.460271", "item": ".zlogin", "msg": "non-zero return code", "rc": 1, "start": "2021-11-09 22:13:30.456177", "stderr": "cp: /Users/ian/.zlogin: No such file or directory", "stderr_lines": ["cp: /Users/ian/.zlogin: No such file or directory"], "stdout": "", "stdout_lines": []}
failed: 127.0.0.1 => {"ansible_loop_var": "item", "changed": true, "cmd": ["cp", "-rp", "~/.zlogout", "~/zsh_original/"], "delta": "0:00:00.004246", "end": "2021-11-09 22:13:30.580230", "item": ".zlogout", "msg": "non-zero return code", "rc": 1, "start": "2021-11-09 22:13:30.575984", "stderr": "cp: /Users/ian/.zlogout: No such file or directory", "stderr_lines": ["cp: /Users/ian/.zlogout: No such file or directory"], "stdout": "", "stdout_lines": []}
changed: [127.0.0.1] => (item=.zprofile)
failed: 127.0.0.1 => {"ansible_loop_var": "item", "changed": true, "cmd": ["cp", "-rp", "~/.zshenv", "~/zsh_original/"], "delta": "0:00:00.004376", "end": "2021-11-09 22:13:30.823566", "item": ".zshenv", "msg": "non-zero return code", "rc": 1, "start": "2021-11-09 22:13:30.819190", "stderr": "cp: /Users/ian/.zshenv: No such file or directory", "stderr_lines": ["cp: /Users/ian/.zshenv: No such file or directory"], "stdout": "", "stdout_lines": []}
failed: 127.0.0.1 => {"ansible_loop_var": "item", "changed": true, "cmd": ["cp", "-rp", "~/.zpreztorc", "~/zsh_original/"], "delta": "0:00:00.004438", "end": "2021-11-09 22:13:30.947302", "item": ".zpreztorc", "msg": "non-zero return code", "rc": 1, "start": "2021-11-09 22:13:30.942864", "stderr": "cp: /Users/ian/.zpreztorc: No such file or directory", "stderr_lines": ["cp: /Users/ian/.zpreztorc: No such file or directory"], "stdout": "", "stdout_lines": []}
...ignoring

2 -

TASK [dotfiles : Run 'setup' target] ********************************************************************************************************
fatal: [127.0.0.1]: FAILED! => {"changed": false, "cmd": "/usr/bin/make setup", "msg": "cp: /Users/ian/Library/ApplicationSupport/Code/User/settings.json: No such file or directory\nmake: *** [setup] Error 1", "rc": 2, "stderr": "cp: /Users/ian/Library/ApplicationSupport/Code/User/settings.json: No such file or directory\nmake: *** [setup] Error 1\n", "stderr_lines": ["cp: /Users/ian/Library/ApplicationSupport/Code/User/settings.json: No such file or directory", "make: *** [setup] Error 1"], "stdout": "Making symlinks to dotfiles...\nfor f in .gitconfig .vimrc ; do \\n\t\trm -f $HOME/$f; \\n\t\tln -s /Users/ian/workspace/settings/dotfiles/$f $HOME/$f; \\n\tdone\nPut zprezto dotfiles...\nfor zpreztof in .zshrc .zpreztorc; do \\n\t\tcp -f /Users/ian/workspace/settings/dotfiles/prezto/$zpreztof $HOME/$zpreztof; \\n\tdone\nPut vscode dotfiles...\nfor vscodef in settings.json; do \\n\t\tcp -f /Users/ian/workspace/settings/dotfiles/vscode/$vscodef $HOME/Library/ApplicationSupport/Code/User/$vscodef; \\n\tdone\n", "stdout_lines": ["Making symlinks to dotfiles...", "for f in .gitconfig .vimrc ; do \", "\t\trm -f $HOME/$f; \", "\t\tln -s /Users/ian/workspace/settings/dotfiles/$f $HOME/$f; \", "\tdone", "Put zprezto dotfiles...", "for zpreztof in .zshrc .zpreztorc; do \", "\t\tcp -f /Users/ian/workspace/settings/dotfiles/prezto/$zpreztof $HOME/$zpreztof; \", "\tdone", "Put vscode dotfiles...", "for vscodef in settings.json; do \", "\t\tcp -f /Users/ian/workspace/settings/dotfiles/vscode/$vscodef $HOME/Library/ApplicationSupport/Code/User/$vscodef; \", "\tdone"]}

Seems like creating symlinks is an issue? I'm new to Ansible.

I have an m1 macbook pro, last years generation.

Thanks