diff --git a/README.rst b/README.rst index a8458ec..3e664eb 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/tasks/copy_rpms.yml b/tasks/copy_rpms.yml new file mode 100644 index 0000000..1372ba7 --- /dev/null +++ b/tasks/copy_rpms.yml @@ -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 diff --git a/tasks/rpm_install.yml b/tasks/rpm_install.yml index fb3ce9a..8d71648 100644 --- a/tasks/rpm_install.yml +++ b/tasks/rpm_install.yml @@ -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: diff --git a/tasks/yum_update_buildah.yml b/tasks/yum_update_buildah.yml index a784876..6aa5759 100644 --- a/tasks/yum_update_buildah.yml +++ b/tasks/yum_update_buildah.yml @@ -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 diff --git a/tasks/yum_update_docker.yml b/tasks/yum_update_docker.yml index 514eeba..ea2e3f5 100644 --- a/tasks/yum_update_docker.yml +++ b/tasks/yum_update_docker.yml @@ -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: diff --git a/templates/yum_update.sh.j2 b/templates/yum_update.sh.j2 index 74ea698..f6cd603 100755 --- a/templates/yum_update.sh.j2 +++ b/templates/yum_update.sh.j2 @@ -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 %}