From 181f4c976488b67caf031ead50c3a2cf0565d568 Mon Sep 17 00:00:00 2001 From: jsherwin <1931307+very-random-man@users.noreply.github.com> Date: Thu, 9 Nov 2023 09:41:59 +0000 Subject: [PATCH 1/8] updated instructions --- README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7ce91ed..8d1106c 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,26 @@ -# Win10 WSL2 development environment provisioner +# Windows WSL2 development environment provisioner -This is an Ansible-based provisioning tool to set up a bunch of Ubuntu cli development tools. It is specifically for Windows 10 WSL2 and was created with destroying and rebuilding the WSL2 environment in mind. It will sync SSH keys between the WSL2 and Win10 user directories so they wont be lost. I'm assuming everything else will be source controlled. +This is an Ansible-based provisioning tool to set up a local Drupal development environment in Windows WSL2. + +The use case is either creating a base setup or keeping multiple WSL2 environments consistent on a single machine +as you would if you use [wsl2-distro-manager](https://github.com/bostrot/wsl2-distro-manager). + +It will sync SSH keys between the WSL2 and Windows user directories so they wont be lost. I'm assuming everything +else will be source controlled. - Run this to install Ansible and provision: ``` ./build.sh ``` -- You can re-run that script to re-provision. You can save a bit of time with `--skip-roles` and it wont fetch all the roles from ansible-galaxy. +- You can re-run that to re-provision. You can save a bit of time with `--skip-roles` and it wont fetch all the + roles from ansible-galaxy. ## So what gets installed? - Keychain - Unison -- Apache -- Apache PHP FPM -- PHP 7.2 +- PHP 8.1 - Composer - Node JS - NPM -- yarn -- Vagrant -- Docker -- Lando - +- DDEV \ No newline at end of file From 3cdd3b0d6617fe53040bf39c930672403ced666f Mon Sep 17 00:00:00 2001 From: jsherwin <1931307+very-random-man@users.noreply.github.com> Date: Thu, 9 Nov 2023 09:42:33 +0000 Subject: [PATCH 2/8] removed unecessary roles --- requirements.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/requirements.yml b/requirements.yml index 350a40b..9b31e3a 100644 --- a/requirements.yml +++ b/requirements.yml @@ -3,9 +3,5 @@ - src: geerlingguy.php - src: geerlingguy.apache-php-fpm - src: geerlingguy.composer -- src: geerlingguy.docker - src: robertdebock.npm -- src: oefenweb.yarn -- src: andrewrothstein.vagrant - src: weareinteractive.unison -# - src: oefenweb.virtualbox From de437780d6564544c0e9e43a8f5f73b8853801b4 Mon Sep 17 00:00:00 2001 From: jsherwin <1931307+very-random-man@users.noreply.github.com> Date: Thu, 9 Nov 2023 09:42:58 +0000 Subject: [PATCH 3/8] force yes to install --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index cccab59..f6eb7e8 100755 --- a/build.sh +++ b/build.sh @@ -50,7 +50,7 @@ else sudo apt update sudo apt install software-properties-common sudo apt-add-repository --yes --update ppa:ansible/ansible - sudo apt install ansible + sudo apt -y install ansible fi PROJECT_ROOT=$PWD From 58691b2553bc0fb87f92644976c06cbed7fea789 Mon Sep 17 00:00:00 2001 From: jsherwin <1931307+very-random-man@users.noreply.github.com> Date: Thu, 9 Nov 2023 09:44:08 +0000 Subject: [PATCH 4/8] upgrade php. apache removed --- inventory/group_vars/all.yml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/inventory/group_vars/all.yml b/inventory/group_vars/all.yml index eef97d9..048773d 100644 --- a/inventory/group_vars/all.yml +++ b/inventory/group_vars/all.yml @@ -1,15 +1,15 @@ -php_version: 7.2 + +check_mode: no + +php_version: '8.1' php_display_errors: "On" php_date_timezone: "Europe/London" +php_enable_webserver: false -apache_create_vhosts: false -apache_remove_default_vhost: true -apache_state: stopped -docker_users: - - "{{ lookup('env','USER') }}" - -lando_version: "v3.0.0-rc.23" +# apache_create_vhosts: false +# apache_remove_default_vhost: true +# apache_state: stopped skip_roles: "{{ skip_roles }}" @@ -17,10 +17,8 @@ profile: | lsb_release -d export WINHOME={{ lookup('env','WINHOME') }} export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1" - export DRUPALVM_ENV=wsl2-local keychain $HOME/.ssh/id_rsa source $HOME/.keychain/{{ lookup('env','NAME') }}-sh - export JAMES=something wsl_conf: | [automount] @@ -39,3 +37,8 @@ gitconfig: | [gc] auto = 256 + + [pull] + rebase = false + [init] + defaultBranch = main From 119c358aab6291422dadd5a9ae3df4341ebaf474 Mon Sep 17 00:00:00 2001 From: jsherwin <1931307+very-random-man@users.noreply.github.com> Date: Thu, 9 Nov 2023 09:45:17 +0000 Subject: [PATCH 5/8] removed apache, docker, lando. Replaced with DDEV. Minor refactoring --- playbook.yml | 153 +++++++++++++++++++++------------------------------ 1 file changed, 62 insertions(+), 91 deletions(-) diff --git a/playbook.yml b/playbook.yml index a385eec..2b877c1 100644 --- a/playbook.yml +++ b/playbook.yml @@ -14,9 +14,8 @@ command: /bin/bash -c "source /home/{{ lookup('env','USER') }}/.profile" responses: passphrase: "{{ ssh_key_passphrase }}\n" - # no_log: true + no_log: true - # - name: Source .profile # shell: source ~/.profile # args: @@ -79,11 +78,6 @@ - name: "No SSH keys exist in $WINHOME or ~/.ssh" when: not winssh_key_check.stat.exists and not ssh_key_check.stat.exists block: - # - name: "No SSH keys exist in $WINHOME or ~/.ssh :: Enter passphrase" - # pause: - # prompt: "Please enter a passphrase for a new SSH key." - # echo: no - # register: ssh_key_passphrase - name: "No SSH keys exist in $WINHOME or ~/.ssh :: Create SSH key in ~/.ssh" no_log: true user: @@ -97,12 +91,23 @@ dest: "{{ lookup('env','WINHOME') }}/.ssh" remote_src: yes - - name: "SSH keys exist in $WINHOME but not in ~/.ssh :: Copy SSH key to ~/.ssh" - copy: - src: "{{ lookup('env','WINHOME') }}/.ssh/" - dest: ~/.ssh - remote_src: yes + - name: "SSH keys exist in $WINHOME but not in ~/.ssh" when: winssh_key_check.stat.exists and not ssh_key_check.stat.exists + block: + + - name: "SSH keys exist in $WINHOME but not in ~/.ssh :: Copy SSH keys to ~/.ssh" + copy: + src: "{{ lookup('env','WINHOME') }}/.ssh/" + dest: ~/.ssh + remote_src: yes + - name: Set private key permissions + file: + path: ~/.ssh/id_rsa + mode: '0600' + - name: Set public key permissions + file: + path: ~/.ssh/id_rsa.pub + mode: '0644' - name: "SSH keys exist in ~/.ssh but not in $WINHOME :: Copy SSH key to $WINHOME/.ssh" copy: @@ -111,6 +116,12 @@ remote_src: yes when: not winssh_key_check.stat.exists and ssh_key_check.stat.exists + - name: Install unzip + become: yes + package: + name: unzip + state: present + - name: Install keychain become: yes package: @@ -120,7 +131,7 @@ - name: Install pexpect become: yes package: - name: python-pexpect + name: python3-pexpect state: present - name: Updating .profile @@ -128,27 +139,25 @@ path: /home/{{ lookup('env','USER') }}/.profile block: "{{ profile }}" - # - name: Set keychain. - # expect: - # command: /bin/bash -c "/usr/bin/keychain $HOME/.ssh/id_rsa" - # responses: - # passphrase: "{{ ssh_key_passphrase }}\n" - # no_log: true - - # - name: Apply Keychain settings. - # shell: source $HOME/.keychain/{{ lookup('env','NAME') }}-sh - # args: - # executable: /bin/bash - - # - name: Source .profile - # shell: source ~/.profile - # # no_log: true - # args: - # executable: /bin/bash - # # stdin: "{{ ssh_key_passphrase }}" - # # stdin_add_newline: yes + - name: Set keychain. + expect: + command: /bin/bash -c "/usr/bin/keychain $HOME/.ssh/id_rsa" + responses: + passphrase: "{{ ssh_key_passphrase }}\n" + no_log: true + - name: Apply Keychain settings. + shell: source $HOME/.keychain/{{ lookup('env','NAME') }}-sh + args: + executable: /bin/bash + - name: Source .profile + shell: source ~/.profile + # no_log: true + args: + executable: /bin/bash + # stdin: "{{ ssh_key_passphrase }}" + # stdin_add_newline: yes - name: Install Galaxy Roles in the requirements.yml file local_action: @@ -174,13 +183,7 @@ unison_user: "{{ lookup('env','USER') }}" ansible_become: yes - - name: Install Apache - include_role: - name: geerlingguy.apache - vars: - ansible_become: yes - - - name: Install PHP versions + - name: Install PHP Versions include_role: name: geerlingguy.php-versions vars: @@ -192,12 +195,6 @@ vars: ansible_become: yes - - name: Install Apache PHP FPM - include_role: - name: geerlingguy.apache-php-fpm - vars: - ansible_become: yes - - name: Install Composer include_role: name: geerlingguy.composer @@ -208,54 +205,28 @@ include_role: name: robertdebock.npm vars: - ansible_become: yes - - - name: Install yarn - include_role: - name: oefenweb.yarn - vars: - ansible_become: yes - - - name: Install vagrant - include_role: - name: andrewrothstein.vagrant - vars: - ansible_become: yes - - - name: Install Docker - register: docker_result - include_role: - name: geerlingguy.docker - vars: - ansible_become: yes + ansible_become: yes - # - name: Install virtualbox - # include_role: - # name: oefenweb.virtualbox - # vars: - # ansible_become: yes + - name: DDEV - Check if exists + stat: + path: /usr/bin/ddev + register: ddev_binary - - name: Reset ssh connection to group change immediately applies. - meta: reset_connection - ignore_errors: True - - - name: Log into docker group - shell: newgrp ; exit - when: not docker_result is skipped + - name: DDEV not installed. Let's do it. + when: not ddev_binary.stat.exists + block: + + - name: DDEV - Download key + shell: 'curl https://apt.fury.io/drud/gpg.key | sudo apt-key add -' + when: ddev_binary.stat.exists == False - - name: Check if Lando is installed - stat: - path: /usr/local/bin/lando - register: lando_check + - name: DDEV - Install apt sources + shell: 'echo "deb https://apt.fury.io/drud/ * *" | sudo tee -a /etc/apt/sources.list.d/ddev.list' + when: ddev_binary.stat.exists == False - - name: Install Lando package from github - become: yes - apt: - deb: "https://github.com/lando/lando/releases/download/{{ lando_version }}/lando-{{ lando_version }}.deb" - when: not lando_check.stat.exists + - name: DDEV - Install + shell: 'sudo apt update && sudo apt install -y ddev' + when: ddev_binary.stat.exists == False - - name: Stop service apache2 so docker will run. - become: yes - service: - name: apache2 - state: stopped \ No newline at end of file + - name: Install mkcert + shell: 'mkcert -install' From 2a5af0f394f2fb609ec08df6a143bb4f58456a1a Mon Sep 17 00:00:00 2001 From: jsherwin <1931307+very-random-man@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:18:22 +0000 Subject: [PATCH 6/8] removed git user details from vars --- build.sh | 4 ++-- init.sh | 7 ------- inventory/group_vars/all.yml | 11 +---------- 3 files changed, 3 insertions(+), 19 deletions(-) delete mode 100644 init.sh diff --git a/build.sh b/build.sh index f6eb7e8..a91d2da 100755 --- a/build.sh +++ b/build.sh @@ -8,8 +8,8 @@ This script will initiate ansible provisioning to build a dev environment. Usage: $PROGNAME [-h,--help] [-s,--skip-roles] - -h, --help: This information. - -s, --skip-roles: Don't reinstall ansible roles via galaxy + -h, --help: This information. + -s, --skip-roles: Don't reinstall ansible roles via galaxy EOF exit 1 diff --git a/init.sh b/init.sh deleted file mode 100644 index 3ec6844..0000000 --- a/init.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -sudo apt update -sudo apt install software-properties-common -sudo apt-add-repository --yes --update ppa:ansible/ansible -sudo apt install ansible - -./provision.sh \ No newline at end of file diff --git a/inventory/group_vars/all.yml b/inventory/group_vars/all.yml index 048773d..d3bc9f2 100644 --- a/inventory/group_vars/all.yml +++ b/inventory/group_vars/all.yml @@ -1,4 +1,3 @@ - check_mode: no php_version: '8.1' @@ -6,11 +5,6 @@ php_display_errors: "On" php_date_timezone: "Europe/London" php_enable_webserver: false - -# apache_create_vhosts: false -# apache_remove_default_vhost: true -# apache_state: stopped - skip_roles: "{{ skip_roles }}" profile: | @@ -25,9 +19,6 @@ wsl_conf: | options="metadata,umask=0033" gitconfig: | - [user] - name = jsherwin - email = 1931307+very-random-man@users.noreply.github.com [core] autocrlf = true @@ -41,4 +32,4 @@ gitconfig: | [pull] rebase = false [init] - defaultBranch = main + defaultBranch = main \ No newline at end of file From 080561e78a0f01cc2b899e84e60f37402acb7840 Mon Sep 17 00:00:00 2001 From: jsherwin <1931307+very-random-man@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:19:15 +0000 Subject: [PATCH 7/8] prompt for git user details --- playbook.yml | 134 +++++++++++++++++++++++++++------------------------ 1 file changed, 70 insertions(+), 64 deletions(-) diff --git a/playbook.yml b/playbook.yml index 2b877c1..3c49e82 100644 --- a/playbook.yml +++ b/playbook.yml @@ -6,15 +6,19 @@ prompt: "[sudo] password for {{ lookup('env','USER') }}" - name: "ssh_key_passphrase" prompt: "Please enter id_rsa SSH key passphrase" + - name: "git_username" + prompt: "Please enter a global git username" + - name: "git_email" + prompt: "Please enter a global git email" tasks: - + - name: Source .profile expect: command: /bin/bash -c "source /home/{{ lookup('env','USER') }}/.profile" responses: passphrase: "{{ ssh_key_passphrase }}\n" - no_log: true + no_log: true # - name: Source .profile # shell: source ~/.profile @@ -49,11 +53,13 @@ path: /home/{{ lookup('env','USER') }}/.gitconfig block: "{{ gitconfig }}" - # - name: Create a symbolic link to WINHOME - # file: - # src: "{{ lookup('env','WINHOME') }}" - # dest: ~/winhome - # state: link + - name: Set git username + shell: "git config --global user.name \"{{ git_username }}\"" + when: git_username|length > 0 + + - name: Set git email + shell: "git config --global user.email \"{{ git_email }}\"" + when: git_email|length > 0 - name: Check if ~/.ssh exists stat: @@ -73,41 +79,41 @@ - name: Check if $WINHOME/.ssh/id_rsa exists stat: path: "{{ lookup('env','WINHOME') }}/.ssh/id_rsa" - register: winssh_key_check + register: winssh_key_check - name: "No SSH keys exist in $WINHOME or ~/.ssh" when: not winssh_key_check.stat.exists and not ssh_key_check.stat.exists - block: - - name: "No SSH keys exist in $WINHOME or ~/.ssh :: Create SSH key in ~/.ssh" - no_log: true - user: - name: "{{ lookup('env','USER') }}" - generate_ssh_key: yes - ssh_key_passphrase: "{{ ssh_key_passphrase }}" - - - name: "No SSH keys exist in $WINHOME or ~/.ssh :: Copy SSH key to $WINHOME/.ssh" - copy: - src: ~/.ssh/ - dest: "{{ lookup('env','WINHOME') }}/.ssh" - remote_src: yes - + block: + - name: "No SSH keys exist in $WINHOME or ~/.ssh :: Create SSH key in ~/.ssh" + no_log: true + user: + name: "{{ lookup('env','USER') }}" + generate_ssh_key: yes + ssh_key_passphrase: "{{ ssh_key_passphrase }}" + + - name: "No SSH keys exist in $WINHOME or ~/.ssh :: Copy SSH key to $WINHOME/.ssh" + copy: + src: ~/.ssh/ + dest: "{{ lookup('env','WINHOME') }}/.ssh" + remote_src: yes + - name: "SSH keys exist in $WINHOME but not in ~/.ssh" when: winssh_key_check.stat.exists and not ssh_key_check.stat.exists block: - - name: "SSH keys exist in $WINHOME but not in ~/.ssh :: Copy SSH keys to ~/.ssh" - copy: - src: "{{ lookup('env','WINHOME') }}/.ssh/" - dest: ~/.ssh - remote_src: yes - - name: Set private key permissions - file: - path: ~/.ssh/id_rsa - mode: '0600' - - name: Set public key permissions - file: - path: ~/.ssh/id_rsa.pub - mode: '0644' + - name: "SSH keys exist in $WINHOME but not in ~/.ssh :: Copy SSH keys to ~/.ssh" + copy: + src: "{{ lookup('env','WINHOME') }}/.ssh/" + dest: ~/.ssh + remote_src: yes + - name: Set private key permissions + file: + path: ~/.ssh/id_rsa + mode: '0600' + - name: Set public key permissions + file: + path: ~/.ssh/id_rsa.pub + mode: '0644' - name: "SSH keys exist in ~/.ssh but not in $WINHOME :: Copy SSH key to $WINHOME/.ssh" copy: @@ -162,12 +168,12 @@ - name: Install Galaxy Roles in the requirements.yml file local_action: command ansible-galaxy install \ - --force \ - --keep-scm-meta \ - -r {{ playbook_dir }}/requirements.yml \ - --roles-path={{ playbook_dir }}/roles + --force \ + --keep-scm-meta \ + -r {{ playbook_dir }}/requirements.yml \ + --roles-path={{ playbook_dir }}/roles when: skip_roles != "yes" - + - name: Make sure the roles directory is being git ignored shell: printf "*\n!.gitignore" > {{ playbook_dir }}/roles/.gitignore @@ -183,50 +189,50 @@ unison_user: "{{ lookup('env','USER') }}" ansible_become: yes - - name: Install PHP Versions + - name: Install PHP Versions include_role: name: geerlingguy.php-versions vars: ansible_become: yes - - name: Install PHP + - name: Install PHP include_role: name: geerlingguy.php vars: ansible_become: yes - - name: Install Composer + - name: Install Composer include_role: name: geerlingguy.composer vars: ansible_become: yes - - name: Install npm + - name: Install npm include_role: name: robertdebock.npm vars: - ansible_become: yes + ansible_become: yes - name: DDEV - Check if exists - stat: + stat: path: /usr/bin/ddev - register: ddev_binary + register: ddev_binary - name: DDEV not installed. Let's do it. - when: not ddev_binary.stat.exists - block: - - - name: DDEV - Download key - shell: 'curl https://apt.fury.io/drud/gpg.key | sudo apt-key add -' - when: ddev_binary.stat.exists == False - - - name: DDEV - Install apt sources - shell: 'echo "deb https://apt.fury.io/drud/ * *" | sudo tee -a /etc/apt/sources.list.d/ddev.list' - when: ddev_binary.stat.exists == False - - - name: DDEV - Install - shell: 'sudo apt update && sudo apt install -y ddev' - when: ddev_binary.stat.exists == False - - - name: Install mkcert - shell: 'mkcert -install' + when: not ddev_binary.stat.exists + block: + + - name: DDEV - Download key + shell: 'curl https://apt.fury.io/drud/gpg.key | sudo apt-key add -' + when: ddev_binary.stat.exists == False + + - name: DDEV - Install apt sources + shell: 'echo "deb https://apt.fury.io/drud/ * *" | sudo tee -a /etc/apt/sources.list.d/ddev.list' + when: ddev_binary.stat.exists == False + + - name: DDEV - Install + shell: 'sudo apt update && sudo apt install -y ddev' + when: ddev_binary.stat.exists == False + + - name: Install mkcert + shell: 'mkcert -install' \ No newline at end of file From b4b8150bd6ebc129e60d5d4f2a9a31430f0ba4c9 Mon Sep 17 00:00:00 2001 From: jsherwin <1931307+very-random-man@users.noreply.github.com> Date: Thu, 9 Nov 2023 16:05:29 +0000 Subject: [PATCH 8/8] added prompt override to add git branch --- inventory/group_vars/all.yml | 9 +++++++++ playbook.yml | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/inventory/group_vars/all.yml b/inventory/group_vars/all.yml index d3bc9f2..916e2a6 100644 --- a/inventory/group_vars/all.yml +++ b/inventory/group_vars/all.yml @@ -14,6 +14,15 @@ profile: | keychain $HOME/.ssh/id_rsa source $HOME/.keychain/{{ lookup('env','NAME') }}-sh +bash: | + if [ "$color_prompt" = yes ]; then + PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w$(__git_ps1)\[\033[00m\]\$ ' + else + PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1)\$ ' + fi + + PROMPT_COMMAND="history -a; history -n" + wsl_conf: | [automount] options="metadata,umask=0033" diff --git a/playbook.yml b/playbook.yml index 3c49e82..a282b99 100644 --- a/playbook.yml +++ b/playbook.yml @@ -145,6 +145,16 @@ path: /home/{{ lookup('env','USER') }}/.profile block: "{{ profile }}" + - name: Updating .bashrc + blockinfile: + path: /home/{{ lookup('env','USER') }}/.bashrc + block: "{{ bash }}" + + - name: Source .bashrc + shell: source ~/.bashrc + args: + executable: /bin/bash + - name: Set keychain. expect: command: /bin/bash -c "/usr/bin/keychain $HOME/.ssh/id_rsa"