Add podman_image and podman_image_info modules (#55103)

* Add podman_image and podman_image_info modules

* Add integration test for podman_image_info

* Change parameter names per feedback

* Add integration tests for podman_image
This commit is contained in:
Sam Doran
2019-04-10 19:28:09 -04:00
committed by Adam Miller
parent e28d08a3c1
commit c2be342ce1
14 changed files with 1150 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
shippable/posix/group3
skip/osx
skip/freebsd
destructive

View File

@@ -0,0 +1,3 @@
FROM quay.io/coreos/alpine-sh
ENV VAR testing
WORKDIR ${VAR}

View File

@@ -0,0 +1,2 @@
dependencies:
- setup_podman

View File

@@ -0,0 +1,144 @@
- name: Test podman_image
when:
- ansible_facts.virtualization_type != 'docker'
- ansible_facts.distribution == 'RedHat'
block:
- name: Pull image
podman_image:
name: quay.io/coreos/alpine-sh
register: pull1
- name: Pull image again
podman_image:
name: quay.io/coreos/alpine-sh
register: pull2
- name: List images
command: podman image ls
register: images
- name: Ensure image was pulled properly
assert:
that:
- pull1 is changed
- pull2 is not changed
- "'alpine-sh' in images.stdout"
- name: Remove image
podman_image:
name: quay.io/coreos/alpine-sh
state: absent
register: rmi1
- name: Remove image again
podman_image:
name: quay.io/coreos/alpine-sh
state: absent
register: rmi2
- name: List images
command: podman image ls
register: images
- name: Ensure image was removed properly
assert:
that:
- rmi1 is changed
- rmi2 is not changed
- "'alpine-sh' not in images.stdout"
- name: Pull a specific version of an image
podman_image:
name: quay.io/coreos/etcd
tag: v3.3.11
register: specific_image1
- name: Pull a specific version of an image again
podman_image:
name: quay.io/coreos/etcd
tag: v3.3.11
register: specific_image2
- name: List images
command: podman image ls
register: images
- name: Ensure specific image was pulled properly
assert:
that:
- specific_image1 is changed
- specific_image2 is not changed
- "'v3.3.11' in images.stdout"
- name: Create a build dir
file:
path: /var/tmp/build
state: directory
- name: Copy Containerfile
copy:
src: Containerfile
dest: /var/tmp/build/Dockerfile
- name: Build OCI image
podman_image:
name: testimage
path: /var/tmp/build
register: oci_build1
- name: Build OCI image again
podman_image:
name: testimage
path: /var/tmp/build
register: oci_build2
- name: Inspect build image
podman_image_info:
name: testimage
register: testimage_info
- name: Ensure OCI image was built properly
assert:
that:
- oci_build1 is changed
- oci_build2 is not changed
- "'localhost/testimage:latest' in testimage_info.images[0]['RepoTags'][0]"
- name: Build Docker image
podman_image:
name: dockerimage
path: /var/tmp/build
build:
format: docker
register: docker_build1
- name: Build Docker image again
podman_image:
name: dockerimage
path: /var/tmp/build
build:
format: docker
register: docker_build2
- name: Inspect build image
podman_image_info:
name: dockerimage
register: dockerimage_info
- name: Ensure Docker image was built properly
assert:
that:
- docker_build1 is changed
- docker_build2 is not changed
- "'localhost/dockerimage:latest' in dockerimage_info.images[0]['RepoTags'][0]"
always:
- name: Cleanup images
podman_image:
name: "{{ item }}"
state: absent
loop:
- quay.io/coreos/alpine-sh
- quay.io/coreos/etcd:v3.3.11
- localhost/testimage
- localhost/dockerimage

View File

@@ -0,0 +1,4 @@
shippable/posix/group2
skip/osx
skip/freebsd
destructive

View File

@@ -0,0 +1,2 @@
dependencies:
- setup_podman

View File

@@ -0,0 +1,26 @@
- name: Test podman_image_info
when:
- ansible_facts.virtualization_type != 'docker'
- ansible_facts.distribution == 'RedHat'
block:
- name: Pull image
command: podman pull quay.io/coreos/etcd
- name: Get info on all images
podman_image_info:
register: all_image_result
- name: Pull another image
command: podman pull quay.io/coreos/dnsmasq
- name: Get info on specific image
podman_image_info:
name: dnsmasq
register: named_image_result
- name:
assert:
that:
- all_image_result.images | length > 0
- named_image_result.images | length == 1
- "'dnsmasq' in named_image_result.images[0]['RepoTags'][0]"

View File

@@ -0,0 +1,13 @@
- block:
- name: Enable extras repo
command: "{{ repo_command[ansible_facts.distribution ~ ansible_facts.distribution_major_version] | default('echo') }}"
- name: Install podman
yum:
name: podman
state: present
when: ansible_facts.pkg_mgr in ['yum', 'dnf']
when:
- ansible_facts.distribution == 'RedHat'
- ansible_facts.virtualization_type != 'docker'
- ansible_facts.distribution_major_version is version_compare('7', '>=')

View File

@@ -0,0 +1,3 @@
repo_command:
RedHat7: yum-config-manager --enable rhui-REGION-rhel-server-extras
# RedHat8: dnf config-manager --enablerepo rhui-REGION-rhel-server-extras