增加额外的模块,以ansible

我已经安装了可以使自动化部署我的系统,我需要一些额外的模块来处理它。 我在可靠的github上下载了模块yumrepo.py,并将其添加到我的库目录中。 但是当我运行,它显示错误ERROR: yumrepo is not a legal parameter of an Ansible Play 。 这是我的configuration文件ansible.cfg。

 inventory = /etc/ansible/hosts library = /etc/ansible/module/ remote_tmp = $HOME/.ansible/tmp 

和我的剧本

 --- - name: Add multiple repositories into the same file (1/2) yumrepo: name: epel description: EPEL YUM repo file: external_repos baseurl: http://download.fedoraproject.org/pub/epel/$releasever/$basearch/ gpgcheck: no 

希望有人帮助我。 非常感谢

你从哪个版本库下载了yumrepo.py

你可能应该使用的是ansible-yumrepo angular色 : https : //github.com/picotrading/ansible-yumrepo ( 关于angular色的更多信息,请看这里)

您可以将其安装在roles目录中,该目录可以与您的剧本位于相同的目录中。 当我从github克隆仓库时,我发现我需要在本地将angular色从ansible-yumrepo重命名为yumrepo

 $ git clone https://github.com/picotrading/ansible-yumrepo.git roles/yumrepo 

然后下面的剧本可以作为你想要做的起点

 - hosts: all roles: - role: yumrepo yumrepo_repos: myrepo1: name: epel description: EPEL YUM repo file: external_repos baseurl: http://download.fedoraproject.org/pub/epel/$releasever/$basearch/ gpgcheck: no 

yumrepo是由ansible-extras提供的问题很可能是这个模块包含yumrepo的版本尚未发布。 如果你检查你安装的extras目录,你可以validation这一点。 我的地址是:

 /usr/local/lib/python2.7/site-packages/ansible/modules/extras/packaging/os/ ls -ltr 

你会看到没有yumrepo.py文件。 因此,一个解决scheme就是有人已经build议将yumrepoangular色克隆到angular色目录中,而不是尝试使用该模块。 如果你完全使用这个模块,你可以将这个yumrepo.py模块从github仓库复制到一个目录中,并且根据http://docs.ansible将它添加到你的ANSIBLE_LIBRARY环境variables中的.com / ansible / developing_modules.html

例如

 export ANSIBLE_LIBRARY=$ANSIBLE_LIBRARY:~/unreleased-ansible-extras 

但是你可能会更好地使用这个angular色,暂时等待下一个版本。

将模块文件放置在playbooks/library它会自动将其取出,不要更改默认的ANSIBLE_LIBRARY vars,只需使用yum / pip安装。 另外,不要把它们放在一个子目录中。

你会有像…

 hosts/hostfile hosts/group_vars/all/custom_vars.yml playbooks/library/plugin.py playbooks/library/plugin2.py playbooks/roles playbooks/my_playbook.yml 

我在/usr/local/lib/python2.7/dist-packages/ansible/modules/extras/find了我的extras软件包,并且通过pip安装了Ansible,但yumrepo仍然不存在。