Browse Source

Merge "Add the possibility to update packages from local rpms using yum."

changes/02/703202/1
Zuul Gerrit Code Review 1 month ago
parent
commit
3c3aa68778
6 changed files with 57 additions and 21 deletions
  1. +20
    -1
      README.rst
  2. +20
    -0
      tasks/copy_rpms.yml
  3. +1
    -17
      tasks/rpm_install.yml
  4. +3
    -0
      tasks/yum_update_buildah.yml
  5. +3
    -1
      tasks/yum_update_docker.yml
  6. +10
    -2
      templates/yum_update.sh.j2

+ 20
- 1
README.rst View File

@@ -45,6 +45,10 @@ Role Variables
* - `target_image`
- `''`
- See modify image variables
* - `rpms_path`
- `''`
- If set, packages present in rpms_path will be updated but dependencies must also be included if required as yum
is called with localupdate.
* - `update_repo`
- `''`
- If set, packages from this repo will be updated. Other repos will only be used for dependencies of these updates.
@@ -195,6 +199,21 @@ In this playbook the tasks\_from is set as a variable instead of an
modified_append_tag: updated
container_build_tool: buildah # or docker
yum_cache: /tmp/containers-updater/yum_cache
rpms_path: /home/stack/rpms

.. code-block::

- hosts: localhost
tasks:
- name: include ansible-role-tripleo-modify-image
import_role:
name: ansible-role-tripleo-modify-image
vars:
tasks_from: yum_update.yml
source_image: docker.io/tripleomaster/centos-binary-nova-api:latest
modified_append_tag: updated
container_build_tool: docker # or buildah
rpms_path: /home/stack/rpms/

Note, if you have a locally installed gating repo, you can add
``update_repo: gating-repo``. This may be the case for the consequent in-place
@@ -242,7 +261,7 @@ network connectivity.
vars:
tasks_from: rpm_install.yml
source_image: docker.io/tripleomaster/centos-binary-nova-api:latest
rpms_path: /foo/bar
rpms_path: /home/stack/rpms
modified_append_tag: -hotfix

Dev install


+ 20
- 0
tasks/copy_rpms.yml View File

@@ -0,0 +1,20 @@
---
- name: List RPMs
find:
paths: "{{ rpms_path }}"
patterns: "^.*?\\.rpm$"
use_regex: true
when: rpms_path is defined
register: context_rpms

- name: Set rpms_list
set_fact:
rpms_list: "{{ context_rpms.files|json_query('[*].path') }}"
when: rpms_path is defined

- name: Copy RPMs to context dir
copy:
src: "{{ item }}"
dest: "{{ modify_dir_path }}"
with_list: "{{ rpms_list }}"
when: rpms_path is defined

+ 1
- 17
tasks/rpm_install.yml View File

@@ -15,23 +15,7 @@
set_fact:
modify_dir_path: "{{ context_dir.path }}"

- name: List RPMs
find:
paths: "{{ rpms_path }}"
patterns: "^.*?\\.rpm$"
use_regex: true
when: rpms_path is defined
register: context_rpms

- name: Set rpms_list
set_fact:
rpms_list: "{{ context_rpms.files|json_query('[*].path') }}"

- name: Copy RPMs to context dir
copy:
src: "{{ item }}"
dest: "{{ modify_dir_path }}"
with_list: "{{ rpms_list }}"
- import_tasks: copy_rpms.yml

- name: Write Dockerfile to {{ modify_dir_path }}
template:


+ 3
- 0
tasks/yum_update_buildah.yml View File

@@ -34,6 +34,8 @@
set_fact:
cache_path: /var/cache/{{ pkg_mgr.split('/')[-1] }}

- import_tasks: copy_rpms.yml

- name: Prepare yum_update.sh script
template:
src: yum_update.sh.j2
@@ -45,6 +47,7 @@
args:
chdir: "{{ yum_repos_dir_path }}"
register: file_repos
when: rpms_path is undefined

- name: Define bind-mount modes for yum cache to be populated or used
when: yum_cache is defined and yum_cache


+ 3
- 1
tasks/yum_update_docker.yml View File

@@ -15,6 +15,8 @@
set_fact:
modify_dir_path: "{{ context_dir.path }}"

- import_tasks: copy_rpms.yml

- name: Copy local file repos to context directory
shell: |
#!/bin/sh
@@ -36,7 +38,7 @@
done
args:
chdir: "{{ modify_dir_path }}"
when: yum_repos_dir_path is defined
when: yum_repos_dir_path is defined and rpms_path is undefined

- name: Write Dockerfile to {{ modify_dir_path }}
template:


+ 10
- 2
templates/yum_update.sh.j2 View File

@@ -5,6 +5,10 @@ set -eou pipefail
PKG="$(command -v dnf || command -v yum)"
PKG_MGR="$(echo ${PKG:(-3)})"

{% if rpms_path is defined %}
$PKG -y localupdate /tmp/*.rpm
rm -f /tmp/*.rpm
{% else %}
if [ $PKG_MGR == "dnf" ]; then
REPOQUERY_CMD="$PKG repoquery"
else
@@ -18,7 +22,6 @@ if [ -n "$1" ] && [[ -n $REPOQUERY_CMD ]]; then
available_versions=$($REPOQUERY_CMD --quiet --provides --disablerepo='*' --enablerepo=$1 -a | sort || true)
uptodate_versions=$(comm -12 <(printf "%s\n" "$installed_versions") <(printf "%s\n" "$available_versions"))


installed=$(printf "%s\n" "$installed_versions" | cut -d= -f1 | sort)
available=$(printf "%s\n" "$available_versions" | cut -d= -f1 | sort)
uptodate=$(printf "%s\n" "$uptodate_versions" | cut -d= -f1 | sort)
@@ -32,7 +35,6 @@ if [ -z "$packages_for_update" ]; then
exit
fi


if [ $PKG_MGR == "dnf" ]; then
plugin=dnf-plugins-core
else
@@ -46,8 +48,14 @@ fi
YUM_OPTS="{% if yum_cache is defined and yum_cache %}--setopt=keepcache=1{% endif %}"

$PKG -y update $YUM_OPTS $packages_for_update
{% endif %}

{% if yum_cache is defined and yum_cache %}
sync
{% else %}
rm -rf /var/cache/$PKG_MGR
{% endif %}

{% if container_build_tool is defined and container_build_tool == 'docker' %}
rm -f /tmp/yum_install.sh
{% endif %}

Loading…
Cancel
Save