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

Puppet apt::source在Ubuntu 18.04上添加不需要的“仿生”存储库条目,ubuntu,puppet,ubuntu-18.04,Ubuntu,Puppet,Ubuntu 18.04,我试图通过Puppet将Ubuntu 18.04实例配置为Kubernetes主节点。为了在Ubuntu18.04服务器上安装kublet、kubeadm和kubectl软件包,我在Puppet主服务器上定义了一个清单,我试图通过Puppet的apt模块在其中添加Kubernetes存储库。清单的相关区块如下所示: include apt class kubernetes { file { '/opt/apt-key.gpg': source => [

我试图通过Puppet将Ubuntu 18.04实例配置为Kubernetes主节点。为了在Ubuntu18.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
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 %>
但我希望它看起来像这样:

deb http://apt.kubernetes.io/ bionic kubernetes-xenial main
deb http://apt.kubernetes.io/ kubernetes-xenial main
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 %>

我该怎么做才能防止这个“仿生”存储库将其放入结果文件中?

结果表明,模块正在做它应该做的事情。在apt::source中为“release”值传入空字符串修复了我的问题。生成/etc/apt/sources.list.d/kubernetes.list文件的模板在提供的存储库列表之前加上提供的“release”值的前缀。在Ubuntu18.04上,当没有提供“release”值时,它似乎解析为“bionic”,这就是它在文件中的结尾。现在我的清单如下所示:

deb http://apt.kubernetes.io/ bionic kubernetes-xenial main
deb http://apt.kubernetes.io/ kubernetes-xenial main
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 %>

根据和,您可以使用apt::source。我怀疑罪魁祸首是您的include apt,它将以某种方式隐式地配置您的服务器,您不需要它,因为您正在使用两种已定义的资源类型。谢谢!查看source.list.epp文件,第5行中使用的“release”值似乎是我的问题的关键。我相信在我的Ubuntu18.04服务器上,“发布版”是解决“仿生”问题的关键。为了解决这个问题,我在Puppet主服务器的清单中提供了一个设置为空字符串的“release”值。这就成功了!奇怪的是,我认为我已经在模板中运行了release变量,并验证了它不是这样。然而,我错了,这是你的问题。当然,你的修复将工作给予。