Puppet apt::source 在 Ubuntu 18.04 上添加不需要的 'bionic' 存储库条目

Puppet apt::source adding unwanted 'bionic' repository entry on Ubuntu 18.04

我正在尝试获取通过 Puppet 配置为 Kubernetes 主节点的 Ubuntu 18.04 实例。为了在 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 文件,但此文件中的存储库条目有不需要的 'bionic' 存储库添加到它。文件中的条目如下所示:

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

但我希望它看起来像这样:

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

我该怎么做才能防止这个 'bionic' 存储库进入生成的文件?

事实证明,该模块正在做它应该做的事情。为 apt::source 中的 'release' 值传递一个空字符串解决了我的问题。生成 /etc/apt/sources.list.d/kubernetes.list 文件 (source.list.epp) 的模板将提供的 'release' 值作为前缀放在提供的存储库列表之前。在 Ubuntu 18.04 上,当没有提供 'release' 值时,它似乎解析为 'bionic',这就是它在文件中的结束方式。现在我的清单看起来像这样:

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 %>