Chef で yum の repository を設定する


背景

Chef でのサーバ構築中に yum update -y を実行し、下記のエラーで構築が失敗していた

Transaction Summary
================================================================================
Install   31 Packages (+27 Dependent packages)
Upgrade  158 Packages

Total download size: 192 M
Downloading packages:
Public key for python2-boto-2.39.0-1.el6.noarch.rpm is not installed
--------------------------------------------------------------------------------
Total                                               12 MB/s | 192 MB  00:15     
Retrieving key from http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
Running transaction check
Running transaction test
STDERR: warning: /var/cache/yum/x86_64/latest/epel/packages/python2-boto-2.39.0-1.el6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Importing GPG key 0x0608B895:
 Userid     : "EPEL (6) <[email protected]>"
 Fingerprint: 8c3b e96a f230 9184 da5c 0dae 3b49 df2a 0608 b895
 From       : http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6


Transaction check error:
  file /usr/bin/pyrsa-decrypt conflicts between attempted installs of python2-rsa-3.4.1-1.el6.noarch and python26-rsa-3.3-2.7.amzn1.noarch
  file /usr/bin/pyrsa-decrypt-bigfile conflicts between attempted installs of python2-rsa-3.4.1-1.el6.noarch and python26-rsa-3.3-2.7.amzn1.noarch
  file /usr/bin/pyrsa-encrypt conflicts between attempted installs of python2-rsa-3.4.1-1.el6.noarch and python26-rsa-3.3-2.7.amzn1.noarch
  file /usr/bin/pyrsa-encrypt-bigfile conflicts between attempted installs of python2-rsa-3.4.1-1.el6.noarch and python26-rsa-3.3-2.7.amzn1.noarch
  file /usr/bin/pyrsa-keygen conflicts between attempted installs of python2-rsa-3.4.1-1.el6.noarch and python26-rsa-3.3-2.7.amzn1.noarch
  file /usr/bin/pyrsa-priv2pub conflicts between attempted installs of python2-rsa-3.4.1-1.el6.noarch and python26-rsa-3.3-2.7.amzn1.noarch
  file /usr/bin/pyrsa-sign conflicts between attempted installs of python2-rsa-3.4.1-1.el6.noarch and python26-rsa-3.3-2.7.amzn1.noarch
  file /usr/bin/pyrsa-verify conflicts between attempted installs of python2-rsa-3.4.1-1.el6.noarch and python26-rsa-3.3-2.7.amzn1.noarch

暫定対処

/etc/yum.repos.d/epel.repoenabled を 0 にする

# This file was generated by Chef
# Do NOT modify this file by hand.

[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
enabled=1
# ------^------- ここを 0 にする
failovermethod=priority
gpgcheck=1
gpgkey=http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6

これを Chef で設定するには

特別な設定をせずに Chef で provision すると、上記ファイルの中身は enabled=1 となってしまう

結論

attribute を

node[:yum][:epel][:enabled] // false

となるように設定する

深追い

yum の cookbook

/etc/yum.repos.d/xxxx.repo のファイルは、 yum の cookbook の template リソースで配置する
https://github.com/chef-cookbooks/yum/blob/381655febf21c38146a3f52bf2aceb193849b84d/providers/repository.rb#L46-L61

配置されるファイルは https://github.com/chef-cookbooks/yum/blob/381655febf21c38146a3f52bf2aceb193849b84d/templates/default/repo.erb#L12-L16

よって、 yum_repository リソースの @config.enabled を設定すれば良い

yum-epel の cookbook

enabled はここで設定している。

変数 repo には文字列 epel が入る。