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 diff --git a/build.sh b/build.sh index cccab59..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 @@ -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 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 eef97d9..916e2a6 100644 --- a/inventory/group_vars/all.yml +++ b/inventory/group_vars/all.yml @@ -1,15 +1,9 @@ -php_version: 7.2 +check_mode: no + +php_version: '8.1' php_display_errors: "On" php_date_timezone: "Europe/London" - -apache_create_vhosts: false -apache_remove_default_vhost: true -apache_state: stopped - -docker_users: - - "{{ lookup('env','USER') }}" - -lando_version: "v3.0.0-rc.23" +php_enable_webserver: false skip_roles: "{{ skip_roles }}" @@ -17,19 +11,23 @@ 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 + +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" gitconfig: | - [user] - name = jsherwin - email = 1931307+very-random-man@users.noreply.github.com [core] autocrlf = true @@ -39,3 +37,8 @@ gitconfig: | [gc] auto = 256 + + [pull] + rebase = false + [init] + defaultBranch = main \ No newline at end of file diff --git a/playbook.yml b/playbook.yml index a385eec..a282b99 100644 --- a/playbook.yml +++ b/playbook.yml @@ -6,17 +6,20 @@ 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 # args: @@ -50,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: @@ -74,35 +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 :: 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: - 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 :: Copy SSH key to ~/.ssh" - copy: - src: "{{ lookup('env','WINHOME') }}/.ssh/" - dest: ~/.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 ~/.ssh but not in $WINHOME :: Copy SSH key to $WINHOME/.ssh" copy: @@ -111,6 +122,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 +137,7 @@ - name: Install pexpect become: yes package: - name: python-pexpect + name: python3-pexpect state: present - name: Updating .profile @@ -128,37 +145,45 @@ 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: Updating .bashrc + blockinfile: + path: /home/{{ lookup('env','USER') }}/.bashrc + block: "{{ bash }}" - # - name: Apply Keychain settings. - # shell: source $HOME/.keychain/{{ lookup('env','NAME') }}-sh - # args: - # executable: /bin/bash + - name: Source .bashrc + shell: source ~/.bashrc + 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: 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 @@ -174,88 +199,50 @@ 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: ansible_become: yes - - name: Install PHP + - name: Install PHP include_role: name: geerlingguy.php vars: ansible_become: yes - - name: Install Apache PHP FPM - include_role: - name: geerlingguy.apache-php-fpm - 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 - - 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 + - name: DDEV - Check if exists + stat: + path: /usr/bin/ddev + register: ddev_binary - # - name: Install virtualbox - # include_role: - # name: oefenweb.virtualbox - # vars: - # ansible_become: yes + - name: DDEV not installed. Let's do it. + when: not ddev_binary.stat.exists + block: - - name: Reset ssh connection to group change immediately applies. - meta: reset_connection - ignore_errors: True + - name: DDEV - Download key + shell: 'curl https://apt.fury.io/drud/gpg.key | sudo apt-key add -' + when: ddev_binary.stat.exists == False - - name: Log into docker group - shell: newgrp ; exit - when: not docker_result is skipped + - 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: Check if Lando is installed - stat: - path: /usr/local/bin/lando - register: lando_check + - name: DDEV - Install + shell: 'sudo apt update && sudo apt install -y ddev' + 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: 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' \ No newline at end of file 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