diff --git a/README.md b/README.md index 45faa95..31d5bef 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ A web-based UI for running playbooks is available via [Ansible Semaphore](https: ├── list.yml # Main playbook for listing VMs ├── install-engine.yml # Main playbook for installing Orka Engine ├── install_android_sdk.yml # Main playbook for installing Android SDK +├── uninstall_android_sdk.yml # Main playbook for uninstalling Android SDK and tooling ├── sdkmanager_install.yml # Main playbook for installing Android SDK platforms and system images ├── sdkmanager_uninstall.yml # Main playbook for uninstalling Android SDK platforms and system images ├── deploy_avd.yml # Main playbook for creating and running Android Virtual Devices @@ -90,7 +91,7 @@ where: #### Install Android SDK -To install the Android SDK (including Java JDK, command-line tools, and platform-tools) on target hosts: +To install the Android SDK and AVD runtime tooling on target hosts: ```bash ansible-playbook install_android_sdk.yml -i dev/inventory @@ -98,14 +99,52 @@ ansible-playbook install_android_sdk.yml -i dev/inventory This will: +- Install Homebrew (if not already present) and ensure `brew shellenv` is loaded in `.zprofile` - Install Eclipse Temurin JDK 21 (if not already present) -- Download and set up Android command-line tools +- Download and set up Android command-line tools at `/opt/android-sdk/cmdline-tools/latest/` - Accept Android SDK licenses -- Install base SDK packages +- Install base SDK packages (`platform-tools`, `emulator`) - Configure `JAVA_HOME`, `ANDROID_HOME`, and `PATH` in the user's `.zshrc` +- Install `socat` via Homebrew (used to relay ADB connections to AVDs) +- Create `/opt/orka/bin/` and `/opt/orka/logs/avd/` directories +- Install the `run-avd` script at `/opt/orka/bin/run-avd` **Note** - To force reinstallation pass `-e "install_android_sdk_force=true"`. +#### Uninstall Android SDK + +To remove the Android SDK and AVD runtime tooling from target hosts. This is the inverse of `install_android_sdk.yml`: + +```bash +ansible-playbook uninstall_android_sdk.yml -i dev/inventory +``` + +By default this will: + +- Remove the `run-avd` script at `/opt/orka/bin/run-avd` +- Remove the AVD log directory at `/opt/orka/logs/avd/` +- Remove the Android SDK directory at `/opt/android-sdk` along with the `JAVA_HOME` / `ANDROID_HOME` / `PATH` block from the user's `.zshrc` +- Remove the Eclipse Temurin JDK 21 installation + +`socat` and Homebrew are left in place by default since both may be used by other tooling on the host. Pass the relevant variables to remove them as well (see below). + +Optional variables (all booleans): + +- `uninstall_android_sdk_run_avd` (default `true`) — remove the `run-avd` script +- `uninstall_android_sdk_orka_dirs` (default `true`) — remove `/opt/orka/logs/avd/` +- `uninstall_android_sdk_sdk_directory` (default `true`) — remove `/opt/android-sdk` and the `ANDROID SDK` block from `.zshrc` +- `uninstall_android_sdk_java` (default `true`) — remove the Temurin JDK 21 installation +- `uninstall_android_sdk_socat` (default `false`) — uninstall `socat` via Homebrew +- `uninstall_android_sdk_homebrew` (default `false`) — uninstall Homebrew itself + +Example removing everything including shared tooling: + +```bash +ansible-playbook uninstall_android_sdk.yml -i dev/inventory \ + -e "uninstall_android_sdk_socat=true" \ + -e "uninstall_android_sdk_homebrew=true" +``` + #### Install Android SDK Platforms and System Images To install an Android SDK platform and its system images on target hosts: diff --git a/roles/uninstall_android_sdk/defaults/main.yml b/roles/uninstall_android_sdk/defaults/main.yml new file mode 100644 index 0000000..e4b2542 --- /dev/null +++ b/roles/uninstall_android_sdk/defaults/main.yml @@ -0,0 +1,11 @@ +--- +uninstall_android_sdk_run_avd: true +uninstall_android_sdk_orka_dirs: true +uninstall_android_sdk_sdk_directory: true +uninstall_android_sdk_java: true +uninstall_android_sdk_socat: false +uninstall_android_sdk_homebrew: false +uninstall_android_sdk_run_avd_path: "/opt/orka/bin/run-avd" +uninstall_android_sdk_orka_log_path: "/opt/orka/logs/avd" +uninstall_android_sdk_home: "/opt/android-sdk" +uninstall_android_sdk_java_home: "/Library/Java/JavaVirtualMachines/temurin-21.jre" diff --git a/roles/uninstall_android_sdk/tasks/main.yml b/roles/uninstall_android_sdk/tasks/main.yml new file mode 100644 index 0000000..bffdfbf --- /dev/null +++ b/roles/uninstall_android_sdk/tasks/main.yml @@ -0,0 +1,57 @@ +--- +- name: Remove run-avd script + become: true + ansible.builtin.file: + path: "{{ uninstall_android_sdk_run_avd_path }}" + state: absent + when: uninstall_android_sdk_run_avd | bool + +- name: Remove orka log directory + become: true + ansible.builtin.file: + path: "{{ uninstall_android_sdk_orka_log_path }}" + state: absent + when: uninstall_android_sdk_orka_dirs | bool + +- name: Uninstall socat + community.general.homebrew: + path: /opt/homebrew/bin + name: socat + state: absent + when: uninstall_android_sdk_socat | bool + +- name: Remove Android SDK directory + become: true + ansible.builtin.file: + path: "{{ uninstall_android_sdk_home }}" + state: absent + when: uninstall_android_sdk_sdk_directory | bool + +- name: Remove ANDROID SDK block from shell profile + ansible.builtin.blockinfile: + path: "/Users/{{ ansible_user }}/.zshrc" + marker: "# {mark} ANDROID SDK" + state: absent + when: uninstall_android_sdk_sdk_directory | bool + +- name: Remove Java JDK + become: true + ansible.builtin.file: + path: "{{ uninstall_android_sdk_java_home }}" + state: absent + when: uninstall_android_sdk_java | bool + +- name: Uninstall Homebrew + ansible.builtin.shell: + cmd: | + NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" + args: + removes: /opt/homebrew/bin/brew + when: uninstall_android_sdk_homebrew | bool + +- name: Remove brew shellenv from zprofile + ansible.builtin.lineinfile: + path: "{{ ansible_env.HOME }}/.zprofile" + line: 'eval "$(/opt/homebrew/bin/brew shellenv)"' + state: absent + when: uninstall_android_sdk_homebrew | bool diff --git a/uninstall_android_sdk.yml b/uninstall_android_sdk.yml new file mode 100644 index 0000000..a59c575 --- /dev/null +++ b/uninstall_android_sdk.yml @@ -0,0 +1,17 @@ +--- +- name: Uninstall Android SDK and tools from target hosts + hosts: hosts + gather_facts: false + module_defaults: + ansible.builtin.setup: + gather_timeout: 20 + pre_tasks: + - name: Gather minimal facts + ansible.builtin.setup: + filter: + - "ansible_env" + - "ansible_user_gid" + tags: + - always + roles: + - role: uninstall_android_sdk