How to install Android SDK with ansible-playbook?
I need to configure Jenkins installation playbook and let Ansible configure Jenkins to integrate with Android
So, I have Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
IP = "192.168.33.55"
VM_NAME = "jenkins"
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "geerlingguy/ubuntu1604" #target OS: Ubuntu 16.04
  config.ssh.insert_key = false
  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.ssh.forward_agent = true
  config.vm.provider :virtualbox do |v|
    v.name = VM_NAME
    v.memory = 1024
    v.cpus = 2
    v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    v.customize ["modifyvm", :id, "--ioapic", "on"]
  end
  config.vm.hostname = VM_NAME
  config.vm.network :private_network, ip: IP
  config.vm.network "forwarded_port", guest: 80, host: 8080
  # Set the name of the VM. See: http://stackoverflow.com/a/17864388/100134
  config.vm.define :jenkins do |jenkins|
  end
  # Ansible provisioner.
  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "jenkins/playbook.yml"
    ansible.inventory_path = "jenkins/inventory"
    ansible.sudo = true
  end
end
And Jenkins installation playbook:
---
- name: Install Jenkins
  hosts: jenkins
  gather_facts: yes
  vars_files:
    - vars/main.yml
  pre_tasks:
    - name: Install Python for Ansible
      raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
  #   changed_when: False
  # - setup: # aka gather_facts
  become: yes
  become_user: root
  remote_user: vagrant
  vars:
     - update_apt_cache: yes
  roles:
    - base
    - geerlingguy.jenkins
    - android-sdk
android-sdk role contains file main.yml with tasks:
---
- name: Download Android SDK
  action: get_url url=https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip dest=/tmp/android.tgz
- name: Make opt dir for user
  action: file path=/opt/adt/ state=directory mode=0777
- name: Unpack Android SDK
  action: unarchive copy=no src=/tmp/android.tgz dest=/opt/adt/ creates=/opt/adt//android-sdk-linux
- name: Chown files
  action: file path=/opt/adt/android-sdk-linux recurse=yes state=directory
- name: Install Android SDK
  action: shell creates=/opt/adt/android-sdk-linux/tools echo y | /opt/adt/android-sdk-linux/tools/android
- name: Configure Android SDK paths
  action: lineinfile dest=/home/vagrant/.bashrc line="{{ item }}"
  with_items:
  - 'export ANDROID_HOME=/opt/adt/android-sdk-linux'
  - 'export ANDROID_TOOLS=$ANDROID_HOME/tools/'
  - 'export ANDROID_PLATFORM_TOOLS=$ANDROID_HOME/platform-tools/'
  - 'export PATH=$PATH:$ANDROID_TOOLS:$ANDROID_PLATFORM_TOOLS'
So, I run my Vargrantfile:
vagrant up
Roles base and geerlingguy.jenkins works, Jenkins VM successfully up. I can open Jenkins page in my browser.
But then android-sdk role starts work, and I see following:
< TASK [android-sdk : Download Android SDK] >
 changed: [jenkins]
< TASK [android-sdk : Make opt dir for user] >
 changed: [jenkins]
< TASK [android-sdk : Unpack Android SDK] >
 changed: [jenkins]
< TASK [android-sdk : Chown files] >
 changed: [jenkins]
< TASK [android-sdk : Install Android SDK] >
fatal: [jenkins]: FAILED! => {"changed": true, "cmd": "echo y | 
/opt/adt/android-sdk-linux/tools/android", "delta": 
"0:00:00.004105", "end": "2017-07-28 17:17:24.446018", "failed": 
true, "rc": 127, "start": "2017-07-28 17:17:24.441913", "stderr": 
"/bin/sh: 1: /opt/adt/android-sdk-linux/tools/android: not found", 
"stderr_lines": ["/bin/sh: 1: /opt/adt/android-sdk-linux/tools/android: not found"],
"stdout": "", "stdout_lines": []}
   jenkins : ok=41   changed=2    unreachable=0    
   failed=1   
   Ansible failed to complete successfully. Any error output should 
   be visible above. Please fix these errors and try again.
But I can see that sdk-tools-linux-3859397.zip contains "tools" directory with "android" shell script inside
My system: Linux Mint 18.2 Sonya, VirtualBox 5.0.40_Ubuntur115130, Ansible 2.3.1.0 and Vagrant 1.9.7.
 
    