在安装新的Docker软件包之前,如何确保已卸载旧的Docker软件包?

时间:2018-10-30 15:57:48

标签: docker puppet

我们有一些较旧的服务器,这些服务器从分发软件包存储库中安装了旧版Docker软件包。可以通过手动安装

$ yum install docker

或更旧的清单

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

我们希望通过“受支持的” official Docker repository and packages模块迁移到puppetlabs-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

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

1 个答案:

答案 0 :(得分:0)

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

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

但是,您不能使用Package['docker'],因为新的puppetlabs-docker模块已经声明了它。您必须执行以下操作:

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

还有许多旧版prerequisite packages也需要删除。

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资源。 gh。

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

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

include docker

这是...合理吗?唯一的可能是排序,您可以使用->探索明确的资源排序。