06 Requirements 文件高级用法
一些控制从哪里下载角色,支持远程源的用法,在 Ansible 1.8 之后支持通过 YMAL 语法的 requirements 文 件实现,但是必须以 yml为文件扩展名。就像这样
ansible-galaxy install -r requirements.yml
扩展名是很重要的,如果 .yml 扩展忘记写了, ansible-galaxy 命令行会假设这个文件是普通格式的,而且会失败,
这里有个例子展示通过多个源下载一些指定版本。 其中也实现了覆盖下载角色的名字到其它名字。
#from galaxy - src: yatesr.timezone
#from github - src: https://github.com/bennojoy/nginx
#from github installing to a relative path - src: https://github.com/bennojoy/nginx
path: vagrant/roles/
#from github, overriding the name and specifying a specific tag - src: https://github.com/bennojoy/nginx
version: master name: nginx_role
#from a webserver, where the role is packaged in a tar.gz - src: https://some.webserver.example.com/files/master.tar.gz
name: http-role
#from bitbucket, if bitbucket happens to be operational right now :) - src: git+http://bitbucket.org/willthames/git-ansible-galaxy
version: v1.4
#from bitbucket, alternative syntax and caveats - src: http://bitbucket.org/willthames/hg-ansible-galaxy
scm: hg
从上面你可以看到,有许多控制命令可以使用去自定义那些角色从哪里获得,保存为什么角色名称。
Roles pulled from galaxy work as with other SCM sourced roles above. To download a role with dependencies, and automatically install those dependencies, the role must be uploaded to the Ansible Galaxy website. 有些角色之间会有依赖关系,想要从依赖关系中自动安装,这个角色需要被上传到 Ansible Galaxy 网站上。
See also
Playbook Roles and Include Statements
关于 Ansible role 的内容
Questions? Help? Ideas? Stop by the list on Google Groups
#ansible IRC chat channel
学员评价