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

This commit is contained in:
Zuul 2020-01-14 15:33:57 +00:00 committed by Gerrit Code Review
commit 3c3aa68778
6 changed files with 57 additions and 21 deletions

View File

@ -45,6 +45,10 @@ Role Variables
* - `target_image` * - `target_image`
- `''` - `''`
- See modify image variables - 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` * - `update_repo`
- `''` - `''`
- If set, packages from this repo will be updated. Other repos will only be used for dependencies of these updates. - 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 modified_append_tag: updated
container_build_tool: buildah # or docker container_build_tool: buildah # or docker
yum_cache: /tmp/containers-updater/yum_cache 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 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 ``update_repo: gating-repo``. This may be the case for the consequent in-place
@ -242,7 +261,7 @@ network connectivity.
vars: vars:
tasks_from: rpm_install.yml tasks_from: rpm_install.yml
source_image: docker.io/tripleomaster/centos-binary-nova-api:latest source_image: docker.io/tripleomaster/centos-binary-nova-api:latest
rpms_path: /foo/bar rpms_path: /home/stack/rpms
modified_append_tag: -hotfix modified_append_tag: -hotfix
Dev install Dev install

20
tasks/copy_rpms.yml Normal file
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

View File

@ -15,23 +15,7 @@
set_fact: set_fact:
modify_dir_path: "{{ context_dir.path }}" modify_dir_path: "{{ context_dir.path }}"
- name: List RPMs - import_tasks: copy_rpms.yml
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 }}"
- name: Write Dockerfile to {{ modify_dir_path }} - name: Write Dockerfile to {{ modify_dir_path }}
template: template:

View File

@ -34,6 +34,8 @@
set_fact: set_fact:
cache_path: /var/cache/{{ pkg_mgr.split('/')[-1] }} cache_path: /var/cache/{{ pkg_mgr.split('/')[-1] }}
- import_tasks: copy_rpms.yml
- name: Prepare yum_update.sh script - name: Prepare yum_update.sh script
template: template:
src: yum_update.sh.j2 src: yum_update.sh.j2
@ -45,6 +47,7 @@
args: args:
chdir: "{{ yum_repos_dir_path }}" chdir: "{{ yum_repos_dir_path }}"
register: file_repos register: file_repos
when: rpms_path is undefined
- name: Define bind-mount modes for yum cache to be populated or used - name: Define bind-mount modes for yum cache to be populated or used
when: yum_cache is defined and yum_cache when: yum_cache is defined and yum_cache

View File

@ -15,6 +15,8 @@
set_fact: set_fact:
modify_dir_path: "{{ context_dir.path }}" modify_dir_path: "{{ context_dir.path }}"
- import_tasks: copy_rpms.yml
- name: Copy local file repos to context directory - name: Copy local file repos to context directory
shell: | shell: |
#!/bin/sh #!/bin/sh
@ -36,7 +38,7 @@
done done
args: args:
chdir: "{{ modify_dir_path }}" 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 }} - name: Write Dockerfile to {{ modify_dir_path }}
template: template:

View File

@ -5,6 +5,10 @@ set -eou pipefail
PKG="$(command -v dnf || command -v yum)" PKG="$(command -v dnf || command -v yum)"
PKG_MGR="$(echo ${PKG:(-3)})" 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 if [ $PKG_MGR == "dnf" ]; then
REPOQUERY_CMD="$PKG repoquery" REPOQUERY_CMD="$PKG repoquery"
else else
@ -18,7 +22,6 @@ if [ -n "$1" ] && [[ -n $REPOQUERY_CMD ]]; then
available_versions=$($REPOQUERY_CMD --quiet --provides --disablerepo='*' --enablerepo=$1 -a | sort || true) 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")) uptodate_versions=$(comm -12 <(printf "%s\n" "$installed_versions") <(printf "%s\n" "$available_versions"))
installed=$(printf "%s\n" "$installed_versions" | cut -d= -f1 | sort) installed=$(printf "%s\n" "$installed_versions" | cut -d= -f1 | sort)
available=$(printf "%s\n" "$available_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) uptodate=$(printf "%s\n" "$uptodate_versions" | cut -d= -f1 | sort)
@ -32,7 +35,6 @@ if [ -z "$packages_for_update" ]; then
exit exit
fi fi
if [ $PKG_MGR == "dnf" ]; then if [ $PKG_MGR == "dnf" ]; then
plugin=dnf-plugins-core plugin=dnf-plugins-core
else else
@ -46,8 +48,14 @@ fi
YUM_OPTS="{% if yum_cache is defined and yum_cache %}--setopt=keepcache=1{% endif %}" YUM_OPTS="{% if yum_cache is defined and yum_cache %}--setopt=keepcache=1{% endif %}"
$PKG -y update $YUM_OPTS $packages_for_update $PKG -y update $YUM_OPTS $packages_for_update
{% endif %}
{% if yum_cache is defined and yum_cache %} {% if yum_cache is defined and yum_cache %}
sync sync
{% else %} {% else %}
rm -rf /var/cache/$PKG_MGR rm -rf /var/cache/$PKG_MGR
{% endif %} {% endif %}
{% if container_build_tool is defined and container_build_tool == 'docker' %}
rm -f /tmp/yum_install.sh
{% endif %}