我一直在尝试编写一本剧本,将 EPEL 存储库添加到可用存储库列表中。
我playbook
有的是:
- hosts: all
# define variables.
vars:
epelReleaseMajorVersion: 7
epelReleaseMinorVersion: 8
tasks:
- name: add epel repo
yum-repository:
name: add epel repo
description: EPEL YUM repo
baseurl: http://dl.fedoraproject.org/pub/epel/$epelReleaseMajorVersion/x86_64/e/epel-release-$epelReleaseMajorVersion-$epelReleaseMinorVersion.noarch.rpm
tags: addEpelRepo
我正在尝试playbook
像这样运行:
ansible-playbook -v -i "localhost," -c local serverSetup.yml
并得到以下错误:
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/root/ansible/playbooks/serverSetup.yml': line 21, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- name: add epel repo
^ here
我的问题:
1.我是否正确使用了变量 epelReleaseMajorVersion 等?
2. 如何解决这个错误?我一直在看文档,但似乎没有很多例子。
答案1
请参阅Ansible yum_repository_module 文档
你的代码应该是
- hosts: all
# define variables.
vars:
epelReleaseMajorVersion: 7
epelReleaseMinorVersion: 8
tasks:
- name: add epel repo
yum_repository:
name: epel_repo
description: EPEL YUM repo
baseurl: http://dl.fedoraproject.org/pub/epel/{{epelReleaseMajorVersion}}/x86_64/
所以你拼错了模块的名称。 Baseurl 是错误的。变量引用错误。并且yum_repository
ansible模块没有任何称为的参数tags