given:
- i have installed android sdk available in path
- i have installed of components id (e.g.
android-23
,extra-android-support
,sys-img-armeabi-v7a-android-19
, etc) using commandandroid update sdk -u -a -t some-ids
question:
how check using command line if components installed or not, based on exact same ids installed them?
bonus: can done without internet connection
i'm going use in ansible playbook script. need avoid running installation command if exists idempotency. although android update sdk
not install installed items, query remote android repository beforehand unnecessary overhead.
i know it's pretty old question, facing same problem while , couldn't find answer.
so i've done in own ansible role (here: "android_sdk") using local facts.
steps need are:
collect variable local facts (in eg. defaults/main.yml):
android_sdk_installed: "{{ ansible_local.android_sdk.sdks_installed if (ansible_local|d() , ansible_local.android_sdk|d() , ansible_local.android_sdk.sdks_installed|d([])) else [] }}"
install specified sdks / build-tools / etc
- name: install android sdks applicable releases shell: /bin/bash -l -c 'echo y | android -s update sdk -u -a -t "{{ item }}"' with_items: - "{{ android_sdk_tools }}" when: item not in android_sdk_installed register: sdk_install_res
where android_sdk_tools example set to:
android_sdk_tools: - "build-tools-23.0.2" - "build-tools-19.1.0"
modify local variable android_sdk_installed (i know it's pretty ugly - it's filtering output previous step clean view)
- name: set local android_sdk_installed fact set_fact: android_sdk_installed="{{ android_sdk_installed|d([]) + [item.item|d()] }}" with_items: | {% set items=[] %} {% item in sdk_install_res.results %} {% if item.item defined %}{% if item.rc defined %} {% if items.append({'item':item.item,'rc':item.rc}) %}{% endif %} {% endif %}{% endif %} {% endfor %} {{ items | to_nice_json }} when: sdk_install_res defined , item.rc == 0
save local facts (it's based on code debops ansible project)
- name: make sure ansible local facts directory present file: path: '/etc/ansible/facts.d' state: 'directory' owner: 'root' group: 'root' mode: '0755' - name: save android_sdk local facts template: src: 'etc/ansible/facts.d/android_sdk.fact.j2' dest: '/etc/ansible/facts.d/android_sdk.fact' owner: 'root' group: 'root' mode: '0644' register: android_sdk_register_local_facts - name: gather facts if modified action: setup when: android_sdk_register_local_facts.changed
where content of template file "android_sdk.fact.j2" is:
{% set android_sdk_tpl_sdks_installed = [] %} {% if (ansible_local|d() , ansible_local.android_sdk|d() , ansible_local.android_sdk.sdks_installed|d()) %} {% element in ansible_local.android_sdk.sdks_installed %} {% set _ = android_sdk_tpl_sdks_installed.append(element) %} {% endfor %} {% endif %} {% element in android_sdk_installed or [] %} {% set _ = android_sdk_tpl_sdks_installed.append(element) %} {% endfor %} { "sdks_installed": {{ android_sdk_tpl_sdks_installed | unique | sort | to_nice_json }} }
hope helps, cheers! :)
Comments
Post a Comment