首页 > 解决方案 > 如何确保在安装新软件包之前卸载旧版 Docker 软件包?

问题描述

我们有一些较旧的服务器,其中安装了从分发包存储库中安装的旧版 Docker 包。手动安装

$ yum install docker

或较旧的清单

package { 'docker': 
    ensure => present,
}

我们希望通过“支持的” puppetlabs-docker模块迁移到官方 Docker 存储库和软件包。

include docker

但是,旧的 Docker 包不会被这个新模块删除或以其他方式管理!

[vagrant@localhost ~]$ sudo -i puppet apply -e 'include docker'
Notice: Compiled catalog for localhost.localdomain in environment production in 0.42 seconds
Notice: /Stage[main]/Docker::Repos/Yumrepo[docker]/ensure: created
Error: Execution of '/bin/yum -d 0 -e 0 -y install docker-ce' returned 1: Error: docker-ce conflicts with 2:docker-1.13.1-75.git8633870.el7.centos.x86_64
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
Error: /Stage[main]/Docker::Install/Package[docker]/ensure: change from 'purged' to 'present' failed: Execution of '/bin/yum -d 0 -e 0 -y install docker-ce' returned 1: Error: docker-ce conflicts with 2:docker-1.13.1-75.git8633870.el7.centos.x86_64
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

我们如何确保在安装新包之前删除旧包?

标签: dockerpuppet

解决方案


您首先要确保不存在旧包。

package { 'docker':
    ensure => absent,
}

但是,您不能使用Package['docker'],因为新的 puppetlabs-docker 模块已经声明了它。你必须做这样的事情:

package { 'legacy-docker':
    ensure => absent,
    name => 'docker',
}

也有许多遗留的必备软件包也需要删除。

package { [
    'docker-client',
    'docker-client-latest',
    'docker-common',
    'docker-latest',
    'docker-latest-logrotate',
    'docker-logrotate',
    'docker-selinux',
    'docker-engine-selinux',
    'docker-engine',
]:
    ensure => absent,
}

所以,总而言之,这种排序似乎是隐含的。

package { 'legacy-docker':
    ensure => absent,
    name => 'docker',
}

package { [
    'docker-client',
    'docker-client-latest',
    'docker-common',
    'docker-latest',
    'docker-latest-logrotate',
    'docker-logrotate',
    'docker-selinux',
    'docker-engine-selinux',
    'docker-engine',
]:
    ensure => absent,
}

include docker

实际上,这似乎会导致清单的后续运行出现问题...删除了常见的二级依赖项!

Error: Execution of '/bin/rpm -e container-selinux-2.68-1.el7.noarch' returned 1: error: Failed dependencies:
        container-selinux >= 2.9 is needed by (installed) docker-ce-18.06.1.ce-3.el7.x86_64
Error: /Stage[main]/Profile::Docker/Package[docker-selinux]/ensure: change from '2:2.68-1.el7' to 'absent' failed: Execution of '/bin/rpm -e container-selinux-2.68-1.el7.noarch' returned 1: error: Failed dependencies:
        container-selinux >= 2.9 is needed by (installed) docker-ce-18.06.1.ce-3.el7.x86_64
Error: Execution of '/bin/rpm -e container-selinux-2.68-1.el7.noarch' returned 1: error: Failed dependencies:
        container-selinux >= 2.9 is needed by (installed) docker-ce-18.06.1.ce-3.el7.x86_64
Error: /Stage[main]/Profile::Docker/Package[docker-engine-selinux]/ensure: change from '2:2.68-1.el7' to 'absent' failed: Execution of '/bin/rpm -e container-selinux-2.68-1.el7.noarch' returned 1: error: Failed dependencies:
        container-selinux >= 2.9 is needed by (installed) docker-ce-18.06.1.ce-3.el7.x86_64

好吧,包资源没有refreshonly一种属性,所以我们需要求助于 exec 资源。啊。

package { 'legacy-docker':
    ensure => absent,
    name => 'docker',
    notify => Exec['autoremove'],
}

exec { 'autoremove':
    command => '/usr/bin/yum -y autoremove',
    refreshonly => true,
}

include docker

这……合理吗?唯一的事情可能是排序,您可以使用->.


推荐阅读