summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrian m. carlson <bk2204@github.com>2022-04-06 17:14:09 +0000
committerbrian m. carlson <bk2204@github.com>2022-04-06 17:14:09 +0000
commit6f382c9e9b4b5f7ddd98a94717aef0b7a314d1c0 (patch)
treeeb299d495b9ce944517df55c3605a78d6495baf2
parentde2b53924c4ce9b1e67679df89cf04c7c31169b2 (diff)
playbooks: add an Ansible playbook to set up a Codespace
The default Codespaces environment has a way to deploy dotfiles, but it doesn't consider that a user might have different dotfiles for home and work. If the default dotfile branch is for home, then it makes it very difficult to automatically deploy the right set of dotfiles for work, since the setup script in the default branch would have to have special logic for both branches to determine the right environment. Let's make it easy to set up a new Codespace by using Ansible and create an Ansible playbook to do this automatically. Ansible is well known to be a robust tool for remote automation using nothing more than SSH, and it's clearly up to the task. Signed-off-by: brian m. carlson <bk2204@github.com>
-rw-r--r--playbooks/codespace-setup.yaml75
1 files changed, 75 insertions, 0 deletions
diff --git a/playbooks/codespace-setup.yaml b/playbooks/codespace-setup.yaml
new file mode 100644
index 0000000..82b364d
--- /dev/null
+++ b/playbooks/codespace-setup.yaml
@@ -0,0 +1,75 @@
+---
+- name: Codespace Setup
+ hosts: all
+ environment:
+ DEBIAN_FRONTEND: noninteractive
+ tasks:
+ - name: Install dependencies
+ apt:
+ pkg:
+ - acl
+ - cargo
+ - dc
+ - git
+ - gopls
+ - gnupg
+ - less
+ - libpam-tmpdir
+ - locales-all
+ - make
+ - man-db
+ - ncurses-term
+ - neovim
+ - perl
+ - ruby
+ - rustc
+ - tmux
+ - xxd
+ - zsh
+ update_cache: true
+ become: yes
+ become_user: root
+ # This is required because otherwise installing the zsh configuration causes
+ # zsh to fail because compinit operates on an insecure directory (~/.zsh).
+ - name: Remove broken ACL
+ shell: 'if [ -n "$(getfacl -s /workspaces)" ]; then setfacl -Rb /workspaces; fi'
+ # We would like sane ownership and permissions here.
+ - name: Undo unexpected ACL ownership
+ command: 'chown -R {{ ansible_user_id }}:{{ ansible_user_id }} /workspaces'
+ become: yes
+ become_user: root
+ - name: Undo unexpected ACL permissions
+ command: 'chmod -R o-rwx /workspaces'
+ - name: Clone dotfiles
+ git:
+ repo: https://github.com/bk2204/dotfiles.git
+ remote: def
+ dest: /workspaces/dotfiles
+ - name: Checkout GitHub for dotfiles
+ shell: 'git checkout GitHub'
+ args:
+ chdir: /workspaces/dotfiles
+ - name: Checkout submodules for dotfiles
+ shell: 'git submodule update --init'
+ args:
+ chdir: /workspaces/dotfiles
+ - name: Deploy dotfiles
+ shell: 'make install'
+ args:
+ chdir: /workspaces/dotfiles
+ - name: Change shell
+ command: 'chsh -s /bin/zsh {{ ansible_user_id }}'
+ become: yes
+ become_user: root
+ - name: Deploy muter
+ command: 'cargo install muter'
+ - name: Deploy scutiger
+ command: 'cargo install scutiger-bin'
+ - name: Change remote name to def
+ shell: 'for i in /workspaces/*; do (cd "$i"; if git remote | grep -qs origin; then git remote rename origin def; fi); done'
+ - name: Set HEAD for remote
+ shell: 'for i in /workspaces/*; do (cd "$i"; git remote set-head def -a); done'
+ - name: Set default branch to dev
+ shell: 'for i in /workspaces/*; do (cd "$i"; b=$(git rev-parse --abbrev-ref refs/remotes/def/HEAD | sed -e "s!.*/!!g"); if git rev-parse --verify "$b" && [ "$b" != dev ]; then git branch -m "$b" dev; fi); done'
+ - name: Install neovim-gtk helper
+ shell: 'cd ~/.vim/plugin && curl -LO https://raw.githubusercontent.com/Lyude/neovim-gtk/main/runtime/plugin/nvim_gui_shim.vim'