diff --git a/roles/flutter/tasks/install-android-sdk.yml b/roles/flutter/tasks/install-android-sdk.yml new file mode 100644 index 0000000..c58ec10 --- /dev/null +++ b/roles/flutter/tasks/install-android-sdk.yml @@ -0,0 +1,61 @@ +- name: create android-sdk directory + become: yes + file: + path: "{{ android.dir }}" + state: directory + owner: "{{ ansible_user_id }}" + +- name: Create temp dir + file: + path: "{{ tmp_dir }}" + state: directory + +- name: "Download Android studio" + unarchive: + src: "https://dl.google.com/android/repository/commandlinetools-linux-{{ android.commandlinetools.version }}.zip" + dest: "{{ tmp_dir }}" + remote_src: yes + +- name: get folder name + shell: ls "{{ tmp_dir }}" + register: dir_name + +- name: create android-sdk cmdline-tools directory + become: yes + file: + path: "{{ android.dir }}/cmdline-tools" + state: directory + owner: "{{ ansible_user_id }}" + +- name: Copy to final directory + command: "cp -ra {{ tmp_dir }}/{{ dir_name.stdout }} {{ android.dir }}/cmdline-tools/latest" + +- name: Remove temp directory + file: + path: "{{ tmp_dir }}" + state: absent + +- name: Create symbolic link for sdkmanager + become: yes + file: + src: "{{ android.dir }}/cmdline-tools/latest/bin/sdkmanager" + dest: "/usr/local/bin/sdkmanager" + state: link + +- name: Create symbolic link for avdmanager + become: yes + file: + src: "{{ android.dir }}/cmdline-tools/latest/bin/avdmanager" + dest: "/usr/local/bin/avdmanager" + state: link + +- name: Install SDK + shell: + cmd: | + yes | sdkmanager --licenses + sdkmanager --install "build-tools;{{ android.sdk.version }}.0.0" + sdkmanager --install "emulator" + sdkmanager --install "patcher;v4" + sdkmanager --install "platform-tools" + sdkmanager --install "platforms;android-{{ android.sdk.version }}" + sdkmanager --install "sources;android-{{ android.sdk.version }}" diff --git a/roles/flutter/tasks/install.yml b/roles/flutter/tasks/install-flutter.yml similarity index 72% rename from roles/flutter/tasks/install.yml rename to roles/flutter/tasks/install-flutter.yml index b0a55cc..a0e91eb 100644 --- a/roles/flutter/tasks/install.yml +++ b/roles/flutter/tasks/install-flutter.yml @@ -1,19 +1,12 @@ -- name: install jmespath for json_query - become: yes - apt: - update_cache: yes - pkg: - - python3-jmespath - - name: Create temp dir file: path: "{{ tmp_dir }}" state: directory -- name: "Flutter" +- name: "Install Flutter" become: yes unarchive: - src: "https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_{{ version }}-stable.tar.xz" + src: "https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_{{ flutter.version }}-stable.tar.xz" dest: "{{ tmp_dir }}" remote_src: yes @@ -23,7 +16,7 @@ - name: Copy to final directory become: yes - command: "cp -ra {{ tmp_dir }}/{{ dir_name.stdout }} {{ flutter_dir }}" + command: "cp -ra {{ tmp_dir }}/{{ dir_name.stdout }} {{ flutter.dir }}" - name: Remove temp directory become: yes @@ -34,13 +27,13 @@ - name: Create symbolic link for flutter become: yes file: - src: "/opt/flutter/bin/flutter" + src: "{{ flutter.dir }}/bin/flutter" dest: "/usr/local/bin/flutter" state: link - name: Create symbolic link for dart become: yes file: - src: "/opt/flutter/bin/dart" + src: "{{ flutter.dir }}/bin/dart" dest: "/usr/local/bin/dart" state: link diff --git a/roles/flutter/tasks/main.yml b/roles/flutter/tasks/main.yml index 4659e11..211ea5e 100644 --- a/roles/flutter/tasks/main.yml +++ b/roles/flutter/tasks/main.yml @@ -1,8 +1,23 @@ -- name: Check if old version exists +- name: install jmespath for json_query + become: yes + apt: + pkg: + - python3-jmespath + +- name: Check if flutter has been installed stat: - path: "{{ flutter_dir }}" + path: "{{ flutter.dir }}" register: flutter_dir_status -- import_tasks: install.yml +- import_tasks: install-flutter.yml when: - - not flutter_dir_status.stat.exists \ No newline at end of file + - not flutter_dir_status.stat.exists + +- name: Check if android-sdk has been installed + stat: + path: "{{ android.dir }}" + register: android_sdk_dir_status + +- import_tasks: install-android-sdk.yml + when: + - not android_sdk_dir_status.stat.exists \ No newline at end of file diff --git a/roles/flutter/vars/main.yml b/roles/flutter/vars/main.yml index 70da778..f85da25 100644 --- a/roles/flutter/vars/main.yml +++ b/roles/flutter/vars/main.yml @@ -1,4 +1,11 @@ --- tmp_dir: /tmp/flutter -flutter_dir: /opt/flutter -version: 3.13.0 \ No newline at end of file +flutter: + dir: /opt/flutter + version: 3.13.0 +android: + dir: /opt/android-sdk + sdk: + version: 34 + commandlinetools: + version: 10406996_latest \ No newline at end of file