ついにMacの環境を自動化してしまいました。brew系とかzshrcとかアプリ系(Chromeとかfirefoxとか)インストールなどを手動でやるのはくそダルいので、ansibleで実装してみました。
■事前準備
https://github.com/RVIRUS0817/ansible_Mac
・git clone/forkで持ってくる
1 | $ git clone https://github.com/RVIRUS0817/ansible_Mac.git |
・run first.sh
1 | $ ./scripts/first.sh |
■構成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | $ tree . ├── README.md ├── ansible.cfg ├── group_vars │ └── all ├── hosts ├── mac.yml ├── roles │ ├── homebrew │ │ └── tasks │ │ └── main.yml │ ├── homebrew-cask │ │ └── tasks │ │ └── main.yml │ └── homedirectory │ ├── files │ └── tasks │ └── main.yml └── scripts └── first.sh |
基本ローカルで叩くのでhostsにはlocalhost、roleにはhomebrewやcask、ホームディレクトリに必要なファイルを管理しています。
・mac.yml
1 2 3 4 5 6 | - hosts: localhost connection: local roles: - homebrew - homebrew-cask - homedirectory |
・group_vars/all
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | $ cat group_vars/all #pip list PIP_TARGETS: - powerline-status #homebrew list BREW_TARGETS: - ansible - python - git - go - htop - openssl - sl - terraform - tmux - tree - wget - zsh - reattach-to-user-namespace - awscli - cask - docker - docker-compose - grep - putty - telnet - tree - watch - w3m - neovim - iproute2mac - watch - jq - peco - ghq - gnu-sed - bat - mkr - knqyf263/trivy/trivy #brewtap list BREWTAP_TARGETS: - mackerelio/mackerel-agent #homebrew-cask list CASK_TARGETS: - firefox - google-chrome - google-japanese-ime - bitbar - karabiner - karabiner-elements - slack - chatwork - evernote - iterm2 - virtualbox - skitch - alfred - near-lock - 1password - skype - messenger - cyberduck - atom - macdown - thunderbird - clipy - macvim - jasper - visual-studio-code - kitematic #homedirectory list HOMEDIR_TARGETS: - { src: roles/homedirectory/files/.config, dest: ~/ } - { src: roles/homedirectory/files/.bash_profile, dest: ~/ } - { src: roles/homedirectory/files/.gitconfig, dest: ~/ } - { src: roles/homedirectory/files/.commit_template, dest: ~/ } - { src: roles/homedirectory/files/.tmux.conf, dest: ~/ } - { src: roles/homedirectory/files/.vimrc, dest: ~/ } - { src: roles/homedirectory/files/.zshrc, dest: ~/ } - { src: roles/homedirectory/files/.gvimrc, dest: ~/ } - { src: roles/homedirectory/files/.vim, dest: ~/ } |
基本group_vars/allでパッケージを管理しますので適当に!
■Run
- first.sh
このシェルはXcodeとbrewをインストールするためのコードとなります。まずこれがないとansibleがインストールできないのでやりましょう。
あとはお好きなようにansibleを叩いてもらえばOKです。
1 | $ ./scripts/first.sh |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | $ ansible-playbook -i hosts mac.yml -KD -C BECOME password: [WARNING]: Ignoring invalid attribute: accept_external_apps [WARNING]: Ignoring invalid attribute: install_options PLAY [localhost] *********************************************************************************************************************** TASK [Gathering Facts] ***************************************************************************************************************** ok: [localhost] TASK [homebrew : Update homebrew] ****************************************************************************************************** ok: [localhost] TASK [homebrew : Install homebrew tap packages] **************************************************************************************** ok: [localhost] => (item=['mackerelio/mackerel-agent']) TASK [homebrew : Install homebrew packages] ******************************************************************************************** ok: [localhost] => (item=['ansible', 'python', 'git', 'go', 'htop', 'openssl', 'sl', 'terraform', 'tmux', 'tree', 'wget', 'zsh', 'reattach-to-user-namespace', 'awscli', 'cask', 'docker', 'docker-compose', 'grep', 'putty', 'telnet', 'tree', 'watch', 'w3m', 'neovim', 'iproute2mac', 'watch', 'jq', 'peco', 'ghq', 'gnu-sed', 'bat', 'mkr', 'knqyf263/trivy/trivy']) TASK [homebrew : Install pip packages] ************************************************************************************************* ok: [localhost] => (item=['powerline-status']) TASK [homebrew-cask : Update homebrew itself first] ************************************************************************************ ok: [localhost] TASK [homebrew-cask : Install Homebrew cask packages] ********************************************************************************** changed: [localhost] => (item=['firefox', 'google-chrome', 'google-japanese-ime', 'bitbar', 'karabiner', 'karabiner-elements', 'slack', 'chatwork', 'evernote', 'iterm2', 'virtualbox', 'skitch', 'alfred', 'near-lock', '1password', 'skype', 'messenger', 'cyberduck', 'atom', 'macdown', 'thunderbird', 'clipy', 'macvim', 'jasper', 'visual-studio-code', 'kitematic']) TASK [homedirectory : Copy home directory .cache/dein] ********************************************************************************* ok: [localhost] => (item={'name': '~/.cache/dein'}) TASK [homedirectory : Copy home directory Files.] ************************************************************************************** ok: [localhost] => (item={'src': 'roles/homedirectory/files/.config', 'dest': '~/'}) ok: [localhost] => (item={'src': 'roles/homedirectory/files/.bash_profile', 'dest': '~/'}) ~省略~ |
はいオッケー!!!
■まとめ
パソコン移行するときに重宝すると思います。Mac買い換えしたときとかも。
リポジトリ化するとカッコいいすね!!
皆さんもぜひ使ってほしいので、プルリクもお待ちしてます!
0件のコメント