ansible android update sdk给出找不到sdkmanager.jar

时间:2015-09-29 06:11:24

标签: android linux bash ubuntu ansible

系统配置: Ubuntu 14.04 ansible 1.9.3

下面的

是main.yml文件

--- 
- 
 hosts: 127.0.0.1
 connection: local
 sudo: yes
 tasks: 
- 
  name: "Install packages to install android sdk"
  with_items: 
    - libgl1-mesa-dev:i386
  apt: "name={{ item }} state=installed"
  sudo: yes
- 
  name: "Install Java"
  with_items: 
    - default-jre
    - default-jdk
    - openjdk-7-jre
    - openjdk-7-jdk
  apt: "name={{ item }} state=installed"
  sudo: yes
- 
  name: "Download sdk tools"
  get_url: url=http://dl.google.com/android/android-sdk_r24.3.4-linux.tgz dest=/opt/android-sdk_r24.3.4-linux
  register: sdk_file
- 
  name: "Unarchiving sdk tools"
  command: tar xzf {{sdk_file.dest}}
  sudo: yes
  args:
    chdir: /opt 
    creates: /opt/android-sdk-linux
- 
  name: "write permissions to android home"
  file: path=/opt/android-sdk-linux state=directory recurse=yes mode=0777
- 
  name: "write permission to sdkmanager.jar"
  file: path=/opt/android-sdk-linux/tools/lib/sdkmanager.jar mode=0777
- 
  name: add android to path
  lineinfile: >
   dest=/etc/environment
   state=present
   backrefs=yes
   regexp='PATH=(["]*)((?!.*?/opt/android-sdk-linux/tools).*?)(["]*)$'
   line="PATH=\1\2:/opt/android-sdk-linux/tools\3"
- 
  name: "Install Android SDKs"
  shell: "android update sdk -u -a -t {{ item }}"
  with_items: 
    - "tools"
    - "platform-tools"
    - "build-tools-23.0.1"
    - "build-tools-22.0.1"
    - "android-23"
    - "android-22"
    - "android-21"
    - "extra"
  args: 
    executable: "/bin/bash"
  environment: 
     PATH: /opt/android-sdk-linux/tools/:$PATH

可从PATH访问android。 还看到我从bash导出/ opt / android-sdk-linux / tools进入我的PATH并且我能够运行android更新命令,同时我还以递归方式将chmod 777权限设置为/ opt / android-sdk-linux但不知何故ansible无法访问它。

我查看了this问题,但这没有帮助。

1 个答案:

答案 0 :(得分:5)

如我所见,您正尝试在 / opt / android-sdk-linux / tools / 中使用android可执行文件。尝试使用它,不再需要PATH

  name: "Install Android SDKs"
  shell: "/opt/android-sdk-linux/tools/android update sdk -u -a -t {{ item }}"
  with_items: 
    - "tools"
    - "platform-tools"
    - "build-tools-23.0.1"
    - "build-tools-22.0.1"
    - "android-23"
    - "android-22"
    - "android-21"
    - "extra"
  args: 
    executable: "/bin/bash"

另外我建议使用以下shell命令来接受所有许可证。

  shell: "echo \"y\" | /opt/android-sdk-linux/tools/android update sdk -u -a -t {{ item }}"