詳細講解6.0 Ansible Galaxy角色倉庫

概況

如今Docker技術應用已經很是廣泛了,相比你們對Docker的鏡像倉庫都不陌生,就是一個官方或者說第三方上傳鏡像的地方,咱們能夠直接下載使用php

相似的,對於Ansible來講角色是最方便咱們複用的基本單位了,Ansible Galaxy(galaxy.ansible.com),就是角色倉庫,存放有大量社區已經寫好的優質角色,咱們直接下載下來便可使用或者參考html

二進制文件通常不放到角色中管理,所以咱們下載的角色基本都是文本文件
galaxy有銀河、星系的意思,沒啥特殊含義,就是起了這麼個名字java

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,能夠經過配置文件修改node

咱們本身也能夠註冊帳號,上傳本身寫好的角色,詳情見官方文檔
因爲角色本質就是一組文件,所以若是真的有內部共享角色的須要,搞個簡單的http server下載,或者基於rsync傳送都OKmysql

galaxy 角色查找

咱們就說一個最簡單、直觀的方法,直接到官網WEB界面galaxy.ansible.com去搜索nginx

以下圖,咱們輸入nginx關鍵詞,搜索相關角色
在這裏插入圖片描述git

點擊第一個進去,看看細節
2021-01-26-10-05-36.pnggithub

關鍵信息一目瞭然,這裏再也不贅述redis

Collections 下載

Collections是Ansible比較新的版本引入的一個概念,它是roles的集合,好比咱們能夠把不少相關的roles定義成Collections,從社區下載Collections,幫助學習借鑑組織多個roles的方法sql

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
相關文章
相關標籤/搜索