Streamline role

Use role defaults rather than set_fact tasks.
Remove empty placeholder files.
Add role meta info.
For variables that can't have a sane default, add precheck tasks to fail early if they are not defined.
This commit is contained in:
Sam Doran 2018-05-02 22:31:08 -04:00
parent 2d87356538
commit 5963894199
11 changed files with 66 additions and 55 deletions

View File

@ -8,20 +8,20 @@ A role to allow modification to container images built for the TripleO project.
| Name | Default Value | Description |
|-------------------|---------------------|----------------------|
| `source_image` | `None` | Mandatory fully qualified reference to the source image to be modified. The supplied Dockerfile will be copied and modified to make the FROM directive match this variable. |
| `modify_dir_path` | `None` | Mandatory path to the directory containing the Dockerfile to modify the image |
| `modified_append_tag` | `None` | String to be appended after the tag to indicate this is a modified version of the source image. Defaults to the output of the command `date +-modified-%Y%m%d%H%M%S` |
| `modified_image` | `{{source_image}}` | If set, the modified image will be tagged with this reference. If the purpose of the image is not changing, it may be enough to rely on `modified_append_tag` to identify that this is a modified version of the source image. `modified_append_tag` will still be appended to this reference. |
| `source_image` | `[undefined]` | Mandatory fully qualified reference to the source image to be modified. The supplied Dockerfile will be copied and modified to make the FROM directive match this variable. |
| `modify_dir_path` | `[undefined]` | Mandatory path to the directory containing the Dockerfile to modify the image |
| `modified_append_tag` | `date +-modified-%Y%m%d%H%M%S` | String to be appended after the tag to indicate this is a modified version of the source image. |
| `modified_image_prefix` | `''` | If set, the modified image will be tagged with this reference. If the purpose of the image is not changing, it may be enough to rely on `modified_append_tag` to identify that this is a modified version of the source image. `modified_append_tag` will still be appended to this reference. |
**Variables used for yum update**
| Name | Default Value | Description |
|-------------------|---------------------|----------------------|
| `source_image` | `None` | See modify image variables |
| `modified_append_tag` | `None` | See modify image variables |
| `modified_image` | `{{source_image}}` | See modify image variables |
| `source_image` | `[undefined]` | See modify image variables |
| `modified_append_tag` | `date +-modified-%Y%m%d%H%M%S` | See modify image variables |
| `modified_image_prefix` | `''` | See modify image variables |
| `yum_repos_dir_path` | `None` | Optional path of directory to be used as `/etc/yum.repos.d` during the update |
| `compare_host_packages` | False | If True, skip yum update when package versions match host package versions |
| `compare_host_packages` | `False` | If `True`, skip yum update when package versions match host package versions |
## Requirements ##

3
defaults/main.yml Normal file
View File

@ -0,0 +1,3 @@
modified_image_prefix: ''
modified_append_tag: "{{ lookup('pipe','date +-modified-%Y%m%d%H%M%S') }}"
compare_host_packages: no

View File

@ -1 +0,0 @@
---

View File

@ -1 +1,21 @@
---
galaxy_info:
author: Steve Baker
description: Modify container images built for TripleO
company: Red Hat
license: Apache 2.0
min_ansible_version: 2.4
platforms:
- name: EL
versions:
- 7
galaxy_tags:
- docker
- container
- openstack
- tripleo
- packaging
- system
dependencies: []

View File

@ -1,9 +1,3 @@
- name: Set default tasks_from
set_fact:
tasks_from: modify_image.yaml
when: tasks_from is undefined
- name: Running tasks from {{ tasks_from }}
include_role:
name: tripleo-modify-image
tasks_from: "{{ tasks_from }}"
- import_tasks: precheck.yml
tags:
- always

View File

@ -1,7 +1,6 @@
- name: Set default facts
include_role:
name: tripleo-modify-image
tasks_from: set_defaults.yml
- import_tasks: precheck.yml
tags:
- always
- name: Copy Dockerfile to Dockerfile.modified
copy:
@ -20,9 +19,9 @@
insertafter: "^FROM "
line: "LABEL modified_append_tag={{ modified_append_tag }}"
- name: Modify image
- name: Modify image
docker_image:
name: "{{ modified_image }}{{ modified_append_tag }}"
name: "{{ modified_image_prefix }}{{ modified_append_tag }}"
path: "{{ modify_dir_path }}"
dockerfile: Dockerfile.modified

11
tasks/precheck.yml Normal file
View File

@ -0,0 +1,11 @@
- name: Ensure that source_image is defined
assert:
that:
- source_image is defined
- source_image | length > 0
- name: Ensure that modify_dir_path is defined
assert:
that:
- modify_dir_path is defined
- modify_dir_path | length > 0

View File

@ -1,9 +0,0 @@
- name: Set default modified_append_tag
set_fact:
modified_append_tag: "{{ lookup('pipe','date +-modified-%Y%m%d%H%M%S') }}"
when: modified_append_tag is undefined
- name: Set default modified_image
set_fact:
modified_image: "{{source_image}}"
when: modified_image is undefined

View File

@ -1,7 +1,6 @@
- name: Set default facts
include_role:
name: tripleo-modify-image
tasks_from: set_defaults.yml
- import_tasks: precheck.yml
tags:
- always
- name: Inspect image
docker_image_facts:
@ -27,15 +26,15 @@
- name: Generate host package json file
block:
- command: |
rpm -qa --qf '"%{NAME}": "%{VERSION}-%{RELEASE}"\n'
register: rpm_query_output
- command: |
rpm -qa --qf '"%{NAME}": "%{VERSION}-%{RELEASE}"\n'
register: rpm_query_output
- copy:
content: "{{ rpm_query_output.stdout | from_yaml | to_nice_json }}"
dest: "{{ context_dir.path }}/host_packages.json"
when: compare_host_packages is defined and compare_host_packages
- copy:
content: "{{ rpm_query_output.stdout | from_yaml | to_nice_json }}"
dest: "{{ context_dir.path }}/host_packages.json"
when: compare_host_packages
- name: Write Dockerfile to {{ context_dir.path }}
template:
@ -46,17 +45,13 @@
copy:
src: yum_update.sh
dest: "{{ context_dir.path }}/yum_update.sh"
mode: 0555
mode: '0555'
- name: Write compare-package-json.py
copy:
src: compare-package-json.py
dest: "{{ context_dir.path }}/compare-package-json.py"
mode: 0555
mode: '0555'
- name: Modify image
include_role:
name: tripleo-modify-image
tasks_from: modify_image.yml
vars:
modify_dir_path: "{{ context_dir.path }}"
import_tasks: modify_image.yml

View File

@ -10,7 +10,7 @@ COPY compare-package-json.py /tmp/
COPY yum.repos.d /etc/
{% endif %}
{% if compare_host_packages is defined %}
{% if compare_host_packages %}
COPY host_packages.json /tmp/
{% endif %}

View File

@ -1 +0,0 @@
---