6.0 Ansible Galaxy角色仓库

概况

现在Docker技术应用已经非常普遍了,相比大家对Docker的镜像仓库都不陌生,就是一个官方或者说第三方上传镜像的地方,我们可以直接下载使用

类似的,对于Ansible来说角色是最方便我们复用的基本单位了,Ansible Galaxy(galaxy.ansible.com),就是角色仓库,存放有大量社区已经写好的优质角色,我们直接下载下来即可使用或者参考

二进制文件一般不放到角色中管理,因此我们下载的角色基本都是文本文件
galaxy有银河、星系的意思,没啥特殊含义,就是起了这么个名字

galaxy 角色下载

ansible-galaxy install role_name
ansible-galaxy install geerlingguy.apache geerlingguy.mysql geerlingguy.php
ansible-galaxy install --roles-path . geerlingguy.apache

#--roles-path . 指定下载目录 . 表示当前目录
#执行输出参考
[root@e5e40c15e020 /data]# ansible-galaxy install --roles-path . geerlingguy.apache
- downloading role 'apache', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-apache/archive/3.1.4.tar.gz
- extracting geerlingguy.apache to /data/geerlingguy.apache
- geerlingguy.apache (3.1.4) was installed successfully

下载的目录默认按照这个顺序~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles,可以通过配置文件修改

我们自己也可以注册账号,上传自己写好的角色,详情见官方文档
由于角色本质就是一组文件,因此如果真的有内部共享角色的需要,搞个简单的http server下载,或者基于rsync传送都OK

galaxy 角色查找

我们就说一个最简单、直观的方法,直接到官网WEB界面galaxy.ansible.com去搜索

如下图,我们输入nginx关键词,搜索相关角色
在这里插入图片描述

点击第一个进去,看看细节
2021-01-26-10-05-36.png

关键信息一目了然,这里不再赘述

Collections 下载

Collections是Ansible比较新的版本引入的一个概念,它是roles的集合,比如我们可以把很多相关的roles定义成Collections,从社区下载Collections,帮助学习借鉴组织多个roles的方法

ansible-galaxy collection install my_namespace.my_collection
ansible-galaxy collection install nginxinc.nginx_core -p .


#-p . 指定下载目录
#执行输出参考
[root@e5e40c15e020 data]# ansible-galaxy collection install nginxinc.nginx_core -p .
[WARNING]: The specified collections path '/data' is not part of the configured Ansible collections paths '/root/.ansible/collections:/usr/share/ansible/collections'. The installed collection won't be
picked up in an Ansible run.
Process install dependency map
Starting collection install process
Installing 'nginxinc.nginx_core:0.3.0' to '/data/ansible_collections/nginxinc/nginx_core'
#告警是说这个安装目录没在配置文件里写,引用的时候找不到,不用管,我们就是下载下来参考的,不直接使用

Collections 查找

同样的到官网WEB界面galaxy.ansible.com搜索即可

2021-01-26-10-21-43.png
2021-01-26-10-21-59.png

列举一些常见优质的roles或collection

#集合
ansible-galaxy collection install nginxinc.nginx_core        -p .
ansible-galaxy collection install ericsysmin.system          -p . 
ansible-galaxy collection install pandemonium1986.openstack  -p .


#角色
ansible-galaxy  install  geerlingguy.apache                   --roles-path  .
ansible-galaxy  install  singleplatform-eng.users             --roles-path  .
ansible-galaxy  install  geerlingguy.java                     --roles-path  .
ansible-galaxy  install  geerlingguy.nginx                    --roles-path  .
ansible-galaxy  install  geerlingguy.pip                      --roles-path  .
ansible-galaxy  install  geerlingguy.nfs                      --roles-path  .
ansible-galaxy  install  geerlingguy.ntp                      --roles-path  .
ansible-galaxy  install  geerlingguy.git                      --roles-path  .
ansible-galaxy  install  geerlingguy.docker                   --roles-path  .
ansible-galaxy  install  geerlingguy.memcached                --roles-path  .
ansible-galaxy  install  robertdebock.bootstrap               --roles-path  .
ansible-galaxy  install  geerlingguy.repo-epel                --roles-path  .
ansible-galaxy  install  geerlingguy.filebeat                 --roles-path  .
ansible-galaxy  install  cloudalchemy.node-exporter           --roles-path  .
ansible-galaxy  install  geerlingguy.mysql                    --roles-path  .
ansible-galaxy  install  yatesr.timezone                      --roles-path  .
ansible-galaxy  install  geerlingguy.nodejs                   --roles-path  .
ansible-galaxy  install  0x0i.systemd                         --roles-path  .
ansible-galaxy  install  dj-wasabi.zabbix-agent               --roles-path  .
ansible-galaxy  install  geerlingguy.homebrew                 --roles-path  .
ansible-galaxy  install  geerlingguy.jenkins                  --roles-path  .
ansible-galaxy  install  geerlingguy.postgresql               --roles-path  .
ansible-galaxy  install  nginxinc.nginx                       --roles-path  .
ansible-galaxy  install  geerlingguy.kibana                   --roles-path  .
ansible-galaxy  install  davidwittman.redis                   --roles-path  .
ansible-galaxy  install  geerlingguy.security                 --roles-path  .
ansible-galaxy  install  geerlingguy.redis                    --roles-path  .
ansible-galaxy  install  cloudalchemy.prometheus              --roles-path  .
ansible-galaxy  install  evrardjp.keepalived                  --roles-path  .
ansible-galaxy  install  geerlingguy.elasticsearch            --roles-path  .
ansible-galaxy  install  geerlingguy.firewall                 --roles-path  .
ansible-galaxy  install  cloudalchemy.grafana                 --roles-path  .
ansible-galaxy  install  geerlingguy.apache-php-fpm           --roles-path  .
ansible-galaxy  install  krzysztof-magosa.docker              --roles-path  .
ansible-galaxy  install  arillso.hosts                        --roles-path  .
ansible-galaxy  install  ansible-thoteam.nexus3-oss           --roles-path  .
ansible-galaxy  install  robertdebock.sysctl                  --roles-path  .
ansible-galaxy  install  elliotweiser.osx-command-line-tools  --roles-path  .
ansible-galaxy  install  geerlingguy.glusterfs                --roles-path  .
ansible-galaxy  install  geerlingguy.ruby                     --roles-path  .
ansible-galaxy  install  willshersystems.sshd                 --roles-path  .
ansible-galaxy  install  geerlingguy.varnish                  --roles-path  .

大家执行下载命令的时候也可以看到,基本上都是到github上去下载的,毕竟这些roles只是一组文本文件,文件大小都不大,我们也可以自己去github上下载并解压,不过那样还是有些麻烦

我自己也把这些优质角色放到了一个国内仓库,方便大家参考

https://gitee.com/as4k/ysansible-roles-examples/tree/master

参考资料

https://docs.ansible.com/ansible/latest/galaxy/user_guide.html
https://galaxy.ansible.com

猜你喜欢

转载自blog.csdn.net/xys2015/article/details/113868421