Add ensure-bazelisk role

This adds a role which installs bazelisk if it is not already
present.  It also adds a test job which exercises the role; the
job will be run on any changes to the new role.

This also removes the noop job since it is no longer needed as
a placeholder.

Change-Id: I69b28b58338b46ec3fea696f9d97be4271ed6ae4
diff --git a/playbooks/test-ensure-bazelisk.yaml b/playbooks/test-ensure-bazelisk.yaml
new file mode 100644
index 0000000..5cd4b14
--- /dev/null
+++ b/playbooks/test-ensure-bazelisk.yaml
@@ -0,0 +1,3 @@
+- hosts: all
+  roles:
+    - ensure-bazelisk
diff --git a/roles/ensure-bazelisk/README.rst b/roles/ensure-bazelisk/README.rst
new file mode 100644
index 0000000..d151c6d
--- /dev/null
+++ b/roles/ensure-bazelisk/README.rst
@@ -0,0 +1,34 @@
+Ensure that bazelisk is present.
+
+If bazelisk is already installed, this role does nothing.  Otherwise,
+it downloads bazelisk from the GitHub and installs it in the user's
+home directory by default.
+
+**Role Variables**
+
+.. zuul:rolevar:: bazelisk_version
+   :default: v1.3.0
+
+   Version of Bazelisk to install
+
+.. zuul:rolevar:: bazelisk_arch
+   :default: linux-amd64
+
+   Architecture to install.
+
+.. zuul:rolevar:: bazelisk_url
+   :default: https://github.com/bazelbuild/bazelisk/releases/download/{{ bazelisk_version }}/bazelisk-{{ bazelisk_arch }}
+
+   The URL from which to download bazelisk.
+
+.. zuul:rolevar:: bazelisk_target
+   :default: "{{ ansible_user_dir }}/.local/bin/bazelisk"
+
+   Where to install bazelisk.  If the role downloads bazelisk, it will
+   set :zuul:rolevar:`bazelisk_executable` to this value as well.
+
+.. zuul:rolevar:: bazelisk_executable
+   :default: bazelisk
+
+   The path to the bazelisk executable.  If this already exists, the
+   role will not perform any further actions.
diff --git a/roles/ensure-bazelisk/defaults/main.yaml b/roles/ensure-bazelisk/defaults/main.yaml
new file mode 100644
index 0000000..813baad
--- /dev/null
+++ b/roles/ensure-bazelisk/defaults/main.yaml
@@ -0,0 +1,6 @@
+bazelisk_version: v1.3.0
+bazelisk_arch: linux-amd64
+bazelisk_url: "https://github.com/bazelbuild/bazelisk/releases/download/{{ bazelisk_version }}/bazelisk-{{ bazelisk_arch }}"
+bazelisk_executable: bazelisk
+# If we have to download it, store it here:
+bazelisk_target: "{{ ansible_user_dir }}/.local/bin/bazelisk"
diff --git a/roles/ensure-bazelisk/tasks/main.yaml b/roles/ensure-bazelisk/tasks/main.yaml
new file mode 100644
index 0000000..efe48c3
--- /dev/null
+++ b/roles/ensure-bazelisk/tasks/main.yaml
@@ -0,0 +1,25 @@
+- name: Check if bazelisk is installed
+  command: bash -c "type -p {{ bazelisk_executable }}"
+  failed_when: false
+  register: bazelisk_installed
+
+- name: Ensure target directory exists
+  file:
+    state: directory
+    path: "{{ bazelisk_target | dirname }}"
+  when: bazelisk_installed.rc != 0
+
+- name: Download bazelisk
+  get_url:
+    url: "{{ bazelisk_url }}"
+    dest: "{{ bazelisk_target }}"
+    mode: '0755'
+  when: bazelisk_installed.rc != 0
+  register: bazelisk_downloaded
+
+# This will apply to further plays and playbooks
+- name: Set bazelisk_executable fact
+  set_fact:
+    bazelisk_executable: "{{ bazelisk_target }}"
+    cacheable: true
+  when: bazelisk_downloaded is changed
diff --git a/zuul.d/project.yaml b/zuul.d/project.yaml
index 2a5dca9..73a1f7f 100644
--- a/zuul.d/project.yaml
+++ b/zuul.d/project.yaml
@@ -1,4 +1,4 @@
 - project:
     check:
       jobs:
-        - noop
+        - test-ensure-bazelisk
diff --git a/zuul.d/test-jobs.yaml b/zuul.d/test-jobs.yaml
new file mode 100644
index 0000000..52002b4
--- /dev/null
+++ b/zuul.d/test-jobs.yaml
@@ -0,0 +1,16 @@
+# Jobs used for testing roles in this repository
+
+# A temporary nodeset until we add this to zuul/config
+- nodeset:
+    name: temp-debian
+    nodes:
+      - name: testnode
+        label: debian-stretch-8G
+
+- job:
+    name: test-ensure-bazelisk
+    run: playbooks/test-ensure-bazelisk.yaml
+    nodeset: temp-debian
+    files:
+      - roles/ensure-bazelisk/.*
+      - playbooks/test-ensure-bazelisk.yaml