From cdff4b7835f8523996fa5c5e68caa8e53dae2a7f Mon Sep 17 00:00:00 2001
From: Ian Wienand <iwienand@redhat.com>
Date: Fri, 8 Nov 2019 11:16:02 +1100
Subject: [PATCH] Role to install podman

A simple role to install podman packages.

Change-Id: I135fab8474b3564bb4ab1f2b19d4645d4a86f560
---
 doc/source/container-roles.rst          |  1 +
 roles/install-podman/README.rst         |  4 ++++
 roles/install-podman/tasks/Ubuntu.yaml  | 12 ++++++++++++
 roles/install-podman/tasks/default.yaml |  3 +++
 roles/install-podman/tasks/main.yaml    |  8 ++++++++
 test-playbooks/install-podman/main.yaml | 14 ++++++++++++++
 zuul-tests.d/container-roles-jobs.yaml  | 14 ++++++++++++++
 7 files changed, 56 insertions(+)
 create mode 100644 roles/install-podman/README.rst
 create mode 100644 roles/install-podman/tasks/Ubuntu.yaml
 create mode 100644 roles/install-podman/tasks/default.yaml
 create mode 100644 roles/install-podman/tasks/main.yaml
 create mode 100644 test-playbooks/install-podman/main.yaml

diff --git a/doc/source/container-roles.rst b/doc/source/container-roles.rst
index 2e2feb360..442eee430 100644
--- a/doc/source/container-roles.rst
+++ b/doc/source/container-roles.rst
@@ -6,6 +6,7 @@ Container Roles
 .. zuul:autorole:: install-docker
 .. zuul:autorole:: install-kubernetes
 .. zuul:autorole:: install-openshift
+.. zuul:autorole:: install-podman
 .. zuul:autorole:: promote-docker-image
 .. zuul:autorole:: pull-from-intermediate-registry
 .. zuul:autorole:: push-to-intermediate-registry
diff --git a/roles/install-podman/README.rst b/roles/install-podman/README.rst
new file mode 100644
index 000000000..0103e63db
--- /dev/null
+++ b/roles/install-podman/README.rst
@@ -0,0 +1,4 @@
+Install podman container manager
+
+**Role Variables**
+
diff --git a/roles/install-podman/tasks/Ubuntu.yaml b/roles/install-podman/tasks/Ubuntu.yaml
new file mode 100644
index 000000000..c8add39ed
--- /dev/null
+++ b/roles/install-podman/tasks/Ubuntu.yaml
@@ -0,0 +1,12 @@
+- name: Install projectatomic PPA
+  apt_repository:
+    repo: 'ppa:projectatomic/ppa'
+    state: present
+  become: yes
+
+- name: Install podman
+  package:
+    name:
+      - podman
+    state: present
+  become: yes
diff --git a/roles/install-podman/tasks/default.yaml b/roles/install-podman/tasks/default.yaml
new file mode 100644
index 000000000..43657eed4
--- /dev/null
+++ b/roles/install-podman/tasks/default.yaml
@@ -0,0 +1,3 @@
+- name: Not implemented
+  fail:
+    msg: Role not implemented on this platform yet
diff --git a/roles/install-podman/tasks/main.yaml b/roles/install-podman/tasks/main.yaml
new file mode 100644
index 000000000..6c8da737d
--- /dev/null
+++ b/roles/install-podman/tasks/main.yaml
@@ -0,0 +1,8 @@
+- name: Find distribution installation
+  include: "{{ item }}"
+  static: no
+  with_first_found:
+    - "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yaml"
+    - "{{ ansible_distribution }}.yaml"
+    - "{{ ansible_os_family }}.yaml"
+    - "default.yaml"
diff --git a/test-playbooks/install-podman/main.yaml b/test-playbooks/install-podman/main.yaml
new file mode 100644
index 000000000..cc2c8487c
--- /dev/null
+++ b/test-playbooks/install-podman/main.yaml
@@ -0,0 +1,14 @@
+- hosts: all
+  roles:
+    - install-podman
+
+- hosts: all
+  tasks:
+
+    - name: Exercise podman
+      command: /usr/bin/podman info
+      register: output
+
+    - name: Debug output
+      debug:
+        msg: '{{ output.stdout }}'
diff --git a/zuul-tests.d/container-roles-jobs.yaml b/zuul-tests.d/container-roles-jobs.yaml
index e6fac892d..ee6beedaa 100644
--- a/zuul-tests.d/container-roles-jobs.yaml
+++ b/zuul-tests.d/container-roles-jobs.yaml
@@ -137,6 +137,19 @@
     run: test-playbooks/install-kubernetes/crio.yaml
     post-run: test-playbooks/install-kubernetes/post.yaml
 
+- job:
+    name: zuul-jobs-test-install-podman
+    description: |
+      Test the install-podman role
+
+      This job tests the install-podman role.  It is not meant to be
+      used directly but rather run on changes to roles in the
+      zuul-jobs repo.
+    files:
+      - roles/install-podman/.*
+      - test-playbooks/install-podman/.*
+    run: test-playbooks/install-podman/main.yaml
+
 # List all the jobs in this file.
 
 - project:
@@ -147,5 +160,6 @@
         - zuul-jobs-test-registry-buildset-registry-k8s-docker
         - zuul-jobs-test-install-kubernetes-docker
         - zuul-jobs-test-install-kubernetes-crio
+        - zuul-jobs-test-install-podman
     gate:
       jobs: *id001