木偶apt :: source在Ubuntu 18.04上添加了不需要的“仿生”存储库条目

时间:2019-02-01 17:50:02

标签: ubuntu puppet ubuntu-18.04

我正在尝试通过Puppet将Ubuntu 18.04实例配置为Kubernetes主节点。为了在Ubuntu 18.04服务器上安装kublet,kubeadm和kubectl软件包,我在Puppet主服务器上定义了一个清单,我试图在其中通过Puppet的apt模块添加Kubernetes存储库。清单的相关块如下:

include apt

class kubernetes {
    file { '/opt/apt-key.gpg':
        source => [
            "https://packages.cloud.google.com/apt/doc/apt-key.gpg"
        ]
    }

    apt::key { 'kubernetes-repository':
        id => '54A647F9048D5688D7DA2ABE6A030B21BA07F4FB',
        source => 'https://packages.cloud.google.com/apt/doc/apt-key.gpg',
    }

    apt::source { 'kubernetes':
        comment => 'This is the kubernetes repository',
        location => 'http://apt.kubernetes.io/',
        repos => 'kubernetes-xenial main',
        key => {
            'id' => '54A647F9048D5688D7DA2ABE6A030B21BA07F4FB',
        },
        include => {
            'deb' => true,
        },
    }

    package { 'kubelet':
        ensure => installed,
    }

    package { 'kubeadm':
        ensure => installed,
    }

    package { 'kubectl':
        ensure => installed,
    }
}

node 'buildserver.mycompany.com' {
    include kubernetes
}

在Ubuntu 18.04服务器上,我执行以下操作以应用清单:

sudo puppet agent -t

我得到以下输出:

Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Loading facts
Info: Caching catalog for buildserver.mycompany.com
Info: Applying configuration version '1549042128'
Error: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install kubelet' returned 100: Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package kubelet
Error: /Stage[main]/Kubernetes/Package[kubelet]/ensure: change from 'purged' to 'present' failed: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install kubelet' returned 100: Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package kubelet
Error: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install kubeadm' returned 100: Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package kubeadm
Error: /Stage[main]/Kubernetes/Package[kubeadm]/ensure: change from 'purged' to 'present' failed: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install kubeadm' returned 100: Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package kubeadm
Error: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install kubectl' returned 100: Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package kubectl
Error: /Stage[main]/Kubernetes/Package[kubectl]/ensure: change from 'purged' to 'present' failed: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install kubectl' returned 100: Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package kubectl
Notice: /Stage[main]/Kubernetes/Apt::Source[kubernetes]/Apt::Setting[list-kubernetes]/File[/etc/apt/sources.list.d/kubernetes.list]/ensure: defined content as '{md5}a0ab4048dbab52eed3aa72b3b6b533cf'
Info: /Stage[main]/Kubernetes/Apt::Source[kubernetes]/Apt::Setting[list-kubernetes]/File[/etc/apt/sources.list.d/kubernetes.list]: Scheduling refresh of Class[Apt::Update]
Info: Class[Apt::Update]: Scheduling refresh of Exec[apt_update]
Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns: Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns: Get:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns: Ign:2 https://packages.cloud.google.com/apt bionic InRelease
Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns: Err:4 https://packages.cloud.google.com/apt bionic Release
Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns:   404  Not Found [IP: 172.217.6.14 443]
Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns: Get:5 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns: Get:6 http://archive.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns: Reading package lists...
Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns: E: The repository 'http://apt.kubernetes.io bionic Release' does not have a Release file.
Error: /Stage[main]/Apt::Update/Exec[apt_update]: Failed to call refresh: '/usr/bin/apt-get update' returned 100 instead of one of [0]
Error: /Stage[main]/Apt::Update/Exec[apt_update]: '/usr/bin/apt-get update' returned 100 instead of one of [0]
Info: Class[Kubernetes]: Unscheduling all events on Class[Kubernetes]
Notice: Applied catalog in 4.19 seconds

事实证明apt :: source正在创建预期的/etc/apt/sources.list.d/kubernetes.list文件,但是此文件中存储库的条目已添加了不需要的“仿生”存储库。文件中的条目如下所示:

deb http://apt.kubernetes.io/ bionic kubernetes-xenial main

但是我期望它看起来像这样:

deb http://apt.kubernetes.io/ kubernetes-xenial main

如何防止该“仿生”存储库进入生成的文件?

1 个答案:

答案 0 :(得分:2)

事实证明,该模块完全按照预期的方式运行。在apt :: source中传递'release'值的空字符串解决了我的问题。生成/etc/apt/sources.list.d/kubernetes.list文件(source.list.epp)的模板在提供的存储库列表之前为提供的“ release”值添加前缀。在Ubuntu 18.04上,当未提供“发布”值时,它似乎解析为“仿生”,这就是它最终在文件中的方式。现在我的清单是这样的:

apt::source { 'kubernetes':
    comment => 'This is the kubernetes repository',
    location => 'http://apt.kubernetes.io/',
    release => '',
    repos => 'kubernetes-xenial main',
    key => {
        'id' => '54A647F9048D5688D7DA2ABE6A030B21BA07F4FB',
    },
    include => {
        'deb' => true,
    },
}

 [<%- if ($opt_architecture) {%>arch=<%= $opt_architecture %><% } %><%if ($opt_architecture and $allow_unsigned) {%> <% }%><% if ($allow_unsigned) {%>trusted=yes<% } %>] <%- } %> <%= $location %> <%= $release %> <%= $repos %>