通过“用户数据”(Amazon Linux)通过cloud-init启用EPEL

时间:2016-09-27 23:44:07

标签: amazon-ec2 yum user-data cloud-init epel

我正在尝试通过“用户数据”功能(使用p7zip)在AWS中启动基于Amazon Linux的EC2实例后安装cloud-init包:

#cloud-config
repo_update: true
repo_upgrade: all

packages:
 - p7zip

但是,由于p7zip在普通存储库中不可用并且需要启用EPEL,因此它似乎无法正确获取包。

我的问题是:使用cloud-init,在初始化EC2实例时如何在获取包之前启用EPEL?

3 个答案:

答案 0 :(得分:1)

#cloud-config
# vim: syntax=yaml
#
# Add yum repository configuration to the system
#
# The following example adds the file /etc/yum.repos.d/epel_testing.repo
# which can then subsequently be used by yum for later operations.
yum_repos:
    # The name of the repository
    epel-testing:
        # Any repository configuration options
        # See: man yum.conf
        #
        # This one is required!
        baseurl: http://download.fedoraproject.org/pub/epel/testing/5/$basearch
        enabled: false
        failovermethod: priority
        gpgcheck: true
        gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
        name: Extra Packages for Enterprise Linux 5 - Testing

答案 1 :(得分:1)

对于更新版本的Amazon Linux,您需要将以下内容添加到cloud-config文件中:

yum_repos:
    epel_custom:
        name: Extra Packages for Enterprise Linux 6 - $basearch
        baseurl: http://download.fedoraproject.org/pub/epel/6/$basearch
        mirrorlist: https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
        failovermethod: priority
        enabled: true
        gpgcheck: true
        gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 

Here是一个有效的云配置文件示例,可以在启动时用作userdata

答案 2 :(得分:0)

以下部分将启用带有GPG的EPEL。请注意,密钥是在初始引导时导入的。

#cloud-config
bootcmd:
  - [ cloud-init-per, once, gpg-key-epel, rpm, "--import", "https://archive.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7" ]
yum_repos:
  epel:
    name: EPEL
    mirrorlist: https://mirrors.fedoraproject.org/mirrorlist?repo=epel-7&arch=$basearch
    enabled: true
    gpgcheck: true
repo_update: true
repo_upgrade: all

来自https://github.com/trajano/terraform-docker-swarm-aws/blob/master/common.cloud-config