2

I'm trying to install the p7zip package after launching an Amazon Linux-based EC2 instance in AWS via the "User Data" feature (using cloud-init):

#cloud-config
repo_update: true
repo_upgrade: all

packages:
 - p7zip

However since p7zip isn't available in the normal repos and requires EPEL to be enabled, it does not appear to be fetching the package properly.

My question is: using cloud-init, how do I enable EPEL before fetching packages when initialising the EC2 instance?

TC Fox
  • 800
  • 3
  • 10
  • 23

3 Answers3

2
#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
Nandeesh
  • 2,245
  • 2
  • 26
  • 37
2

For more recent versions of Amazon Linux, you need to add the following to cloud-config file:

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 is an example of a working cloud-config file that can be used at boot as userdata.

f-x
  • 31
  • 3
0

The following sections will enable EPEL with GPG. Note that the key is imported at initial boot.

#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

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

Archimedes Trajano
  • 22,850
  • 10
  • 113
  • 154