Centos 如何使用ansible安装yum存储库密钥?

Centos 如何使用ansible安装yum存储库密钥?,centos,ansible,passenger,yum,gnupg,Centos,Ansible,Passenger,Yum,Gnupg,我试过: 但是为了让它工作,我需要ssh到机器上,确认导入密钥(通过运行任何yum命令,例如yum list installed),然后继续设置。有没有一种方法可以自动完成 UPD以下是ansible所说的: TASK [nginx : Add repository key] ********************************************** changed: [default] TASK [nginx : Install nginx with 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"}

因此,在这两种情况下都确实导入了密钥,但要使用密钥,必须对其进行确认。

通过直接使用
-y
开关运行
yum
(并使用
rpm\u-key
模块,如果有)来修复该密钥:


添加存储库和存储库密钥后,只需使用以下内容更新该repo的元数据:

- name: update repo cache for the new repo
  command: yum -q makecache -y --disablerepo=* --enablerepo=passenger

然后像以前一样继续执行
yum:name=…

您应该能够使用
expect
模块而不是命令一来自动执行用户交互
rpm\u键
模块是否出错?或者你为什么试图用
命令
模块添加密钥?@knowhy我在问题中添加了更多细节。但要回答你的问题,不,没有错误。只是仅仅安装软件包是不够的。请参阅上面的
ansible
输出。这是一个有趣的建议,但不幸的是它成功了。另外,最好不要每次都运行。不要让它看起来像是改变了什么,而实际上并没有。由于
命令
任务被标记为默认更改。此外,此处不需要开关
-q
。但这当然没什么大不了的。我遇到了一个看起来像是有回购密钥处理的,所以它可能是一个可以尝试的东西。我还在中打开了一个报告,因为它确实应该由
rpm\u key
模块正确处理。对不起,我的错,我忘了它也需要EPEL存储库。随着它的成功。请考虑添加它或链接到你的答案。第二个想法,我认为<代码> ym MaCeCase<代码>不能传达意图,所以<代码> YUM -Y安装< /C>看起来是个更好的选择。
- name: Install nginx with passenger
  command: yum -y install {{ item }}
  with_items: [nginx, passenger]
- name: update repo cache for the new repo
  command: yum -q makecache -y --disablerepo=* --enablerepo=passenger