我试了two ways:
- name: Add repository
yum_repository:
# from https://oss-binaries.phusionpassenger.com/yum/definitions/el-passenger.repo
name: passenger
description: Passenger repository
baseurl: https://oss-binaries.phusionpassenger.com/yum/passenger/el/$releasever/$basearch
repo_gpgcheck: 1
gpgcheck: 0
enabled: 1
gpgkey: https://packagecloud.io/gpg.key
sslverify: 1
sslcacert: /etc/pki/tls/certs/ca-bundle.crt
- name: Add repository key (option 1)
rpm_key:
key: https://packagecloud.io/gpg.key
- name: Add repository key (option 2)
command: rpm --import https://packagecloud.io/gpg.key
- name: Install nginx with passenger
yum: name={{ item }}
with_items: [nginx, passenger]
但要使其工作,我需要ssh到机器,确认导入密钥(通过运行任何yum
命令,例如yum list installed
),然后继续配置。有没有办法自动完成?
UPD 这里是ansible
所说的内容:
TASK [nginx : Add repository key] **********************************************
changed: [default]
TASK [nginx : Install nginx with passenger] ************************************
failed: [default] (item=[u'nginx', u'passenger']) => {"failed": true, "item": ["nginx", "passenger"], "msg": "Failure talking
to yum: failure: repodata/repomd.xml from passenger: [Errno 256] No more mirrors to try.\nhttps://oss-binaries.phusionpassen
ger.com/yum/passenger/el/7/x86_64/repodata/repomd.xml: [Errno -1] repomd.xml signature could not be verified for passenger"}
因此,密钥确实在两种情况下都被导入,但是要使用它必须得到确认。
答案 0 :(得分:1)
通过直接使用yum
开关运行-y
来修复此问题(并使用rpm_key
模块,如果有的话):
- name: Install nginx with passenger
command: yum -y install {{ item }}
with_items: [nginx, passenger]
答案 1 :(得分:0)
添加存储库和存储库密钥后,只需使用以下命令更新该repo的元数据:
- name: update repo cache for the new repo
command: yum -q makecache -y --disablerepo=* --enablerepo=passenger
然后像以前一样继续yum: name=...
。