一,介绍ansible galaxy

Ansible Galaxy [https://galaxy.ansible.com]是一个Ansible内容公共资源库,这些内容由许许多多Ansible管理员和用户编写。它包含数千个Ansible角色,具有可搜索的数据库,可帮助Ansible用户确定或许有助于他们完成管理任务的角色。Ansible Galaxy含有面向新的Ansible用户和角色开发人员的文档和视频链接。
此外,用于从Ansible Galaxy获取和管理角色的ansible-galaxy命令也可用于为您的项目获取和管理自有的git存储库中的角色。

1.1,获取Ansible Galaxy帮助

通过Ansible Galaxy网站主页上的Documenttaion标签,可以进入描述如何使用Ansible Galaxy的页面。其中包含了介绍如何从Ansible Galaxy下载和使用角色的内容。该页面也提供关于如何开发角色并上传到Ansible Galaxy的说明。

1.2,浏览Ansible Galaxy中的角色

通过Ansible Galaxy网站主页上左侧的Search标签,用户可以访问关于Ansible Galaxy上发布的角色的信息。用户可以使用标记通过角色的名称或通过其他角色属性来搜索Ansible角色。结果按照Best Match分数降序排列,此分数依据角色质量、角色受欢迎程度和搜索条件计算而得。

二,Ansible Galaxy命令行工具

2.1,从命令行搜索角色

[root@ansible ansible]# ansible-galaxy  --help
usage: ansible-galaxy [-h] [--version] [-v] TYPE ...Perform various Role and Collection related operations.positional arguments:TYPEcollection   Manage an Ansible Galaxy collection.     //管理ansible galaxy的collectionrole         Manage an Ansible Galaxy role.     //管理ansible galaxy的角色optional arguments:--version      show program's version number, config file location,configured module search path, module location, executablelocation and exit-h, --help     show this help message and exit-v, --verbose  verbose mode (-vvv for more, -vvvv to enable connectiondebugging)[root@ansible ansible]# ansible-galaxy role --help
usage: ansible-galaxy role [-h] ROLE_ACTION ...positional arguments:ROLE_ACTIONinit       Initialize new role with the base structure of a role.remove     Delete roles from roles_path.      //从角色目录删除角色,但这个角色目录必须是安装的角色,才能去删除delete     Removes the role from Galaxy. It does not remove or alter theactual GitHub repository.list       Show the name and version of each role installed in the     //在角色目录里面查看名字和版本对于每个角色已经安装的角色roles_path.search     Search the Galaxy database by tags, platforms, author andmultiple keywords.      //从galaxy数据库去查找角色,用它的版本,平台,作者,关键字去搜索import     Import a role     //导入角色setup      Manage the integration between Galaxy and the given source.    //管理集成,在galaxy和指定的源之间去管理集成info       View more details about a specific role.    //看详细信息install    Install role(s) from file(s), URL(s) or Ansible Galaxy    //安装角色从文件,URL(网上的某一个链接文件去装)或者ansible的galaxyoptional arguments:-h, --help   show this help message and exit[root@ansible roles]# ansible-galaxy role init nginx    //创建角色并初始化,role是面向对象的
- Role nginx was created successfully
[root@ansible roles]# tree nginx/
nginx/
├── defaults
│   └── main.yml
├── files
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
├── README.md
├── tasks
│   └── main.yml
├── templates
├── tests
│   ├── inventory
│   └── test.yml
└── vars└── main.yml8 directories, 8 files[root@ansible ~]# ansible-galaxy role search httpd    //查找角色Found 329 roles matching your search:Name                                                          Description----                                                          -----------2kloc.trellis-monit                                           Install and configure Monit service in Trellis.aarunmichael.base_httpd                                       your role descriptiona_arvind_k.base_httpd                                         your role descriptionabdelmouhssine.hardening_cis_apache_http_server_2_4_benchmark CLOUD APPLICATION AND SECURITY ENGINEERabdusamy.web_server_role                                      Deploy http virtual hosts using customized configurationacandid.httpd                                                 Install httpd and ssl.acropia.httpd                                                 IT Professionaladellam.389ds_server                                          Installs 389DS LDAP server. Also configures TLS, logging, c>ahuffman.patching                                             An Ansible Role to perform automated patching of systems.ahuffman.sat6_create_hosts                                    An Ansible role to create new virtual and bare-metal hosts >aishee.ansible_redhat_centos_7                                Apply RHEL 7 CIS BaselineAlbanAndrieu.ansible-workstation                              A role for installing workstationalikins.certbot                                               Installs and configures Certbot (for Let's Encrypt).alikins.php                                                   PHP for RedHat/CentOS/Fedora/Debian/Ubuntu.alvistack.httpd                                               Ansible Role for Apache HTTP Server Installationamanbolat.ansible_role_certbot                                Installs and configures Certbot (for Let's Encrypt).aminvakil.httpd_initial                                       Installs and Configures Apache HTTPD on Debian Buster

2.2,从Ansible Galaxy安装角色

ansible-galaxy install子命令从Ansible Galaxy下载角色,并将它安装到控制节点本地。

默认情况下,角色安装到用户的roles_path下的第一个可写目录中。根据为Ansible设置的默认roles_path,角色通常将安装到用户的~/.ansible/roles目录。默认的roles_path可能会被用户当前Ansible配置文件或环境变量ANSIBLE_ROLES_PATH覆盖,这将影响ansible-galaxy的行为。

用户可以通过使用-p DIRECTORY选项,指定具体的目录来安装角色。

[root@ansible playbook]# cd roles/
[root@ansible roles]# ansible-galaxy role install robertdebock.httpd -p .   //把角色安装到当前位置
- downloading role 'httpd', owned by robertdebock
- downloading role from https://github.com/robertdebock/ansible-role-httpd/archive/7.0.0.tar.gz
- extracting robertdebock.httpd to /etc/ansible/playbook/roles/robertdebock.httpd
- robertdebock.httpd (7.0.0) was installed successfully
[root@ansible roles]# ls
robertdebock.httpd [root@ansible roles]# ansible-galaxy role install robertdebock.httpd -p ./httpd
- downloading role 'httpd', owned by robertdebock
- downloading role from https://github.com/robertdebock/ansible-role-httpd/archive/7.0.0.tar.gz
- extracting robertdebock.httpd to /etc/ansible/playbook/roles/httpd/robertdebock.httpd
- robertdebock.httpd (7.0.0) was installed successfully
[root@ansible roles]# lshttpd robertdebock.httpd [root@ansible roles]# ansible-galaxy  list -p .    //在当前位置查找角色,如果当前位置是不在它的路径下面的,就可以指定位置,如果当前位置没有的话就会去找其他地方,当前位置有的话,其他地方也去找
# /etc/ansible/playbook/roles
- timesync, (unknown version)
- selinux, (unknown version)
- httpd, (unknown version)
- apache, (unknown version)
- nginx, (unknown version)
- robertdebock.httpd, 7.0.0
# /usr/share/ansible/roles
- linux-system-roles.kdump, (unknown version)
- linux-system-roles.network, (unknown version)
- linux-system-roles.postfix, (unknown version)
- linux-system-roles.selinux, (unknown version)
- linux-system-roles.storage, (unknown version)
- linux-system-roles.timesync, (unknown version)
- rhel-system-roles.kdump, (unknown version)
- rhel-system-roles.network, (unknown version)
- rhel-system-roles.postfix, (unknown version)
- rhel-system-roles.selinux, (unknown version)
- rhel-system-roles.storage, (unknown version)
- rhel-system-roles.timesync, (unknown version)
# /etc/ansible/roles
[WARNING]: - the configured path /root/.ansible/roles does not exist.[root@ansible roles]# ansible-galaxy  role remove robertdebock.httpd -p .   //移除,自己创建的也可以移除
- successfully removed robertdebock.httpd

2.3,管理下载的角色

ansible-galaxy命令也可管理本地的角色,如位于playbook项目的roles目录中的角色。ansible-galaxy list子命令列出本地找到的角色。

ansible-galaxy list

使用ansible-galaxy remove子命令本地删除角色。

ansible-galaxy  role remove robertdebock.httpd

使用ansible galaxy部署角色相关推荐

  1. RHCE-B5. 使用Ansible Galaxy 安装角色

    红帽RHCE考试下午-RHCE(RH294) RH294任务概览 考试时间4个小时,6台虚拟机,15道题 原来通过脚本或者集群做的题现在都需要使用playbook实现 考试时大概有6台虚拟服务器,都已 ...

  2. 使用Ansible Galaxy 安装角色

    使用 Ansible Galaxy 和要求文件 /home/student/ansible/roles/requirements.yml, 从以下 URL 下载角色并安装到 /home/student ...

  3. Ansible Galax在线角色的使用

    Ansible Galax在线角色的使用 1.使用ansible galaxy部署角色 1.1.介绍ansible galaxy Ansible Galaxy https://galaxy.ansib ...

  4. 第九章、Ansible基于roles角色管理大项目

    第九章.Ansible基于roles角色管理大项目 文章目录 一.利用角色构造ansible playbook 1.在playbook中使用ansible角色 2.控制执行顺序 3.导入角色任务 二. ...

  5. ansible Galaxy的应用

    ansible Galaxy的应用 1 ansible Galaxy介绍 Ansible Galaxy [https://galaxy.ansible.com]是一个Ansible内容公共资源库,这些 ...

  6. 自动化工具后起之秀Ansible的部署实践

    本文转自微信号EAWorld.扫描下方二维码,关注成功后,回复"普元方法+",将会获得热门课堂免费学习机会! 从早期手动加脚本的部署方式,到后来自动化工具(chef, puppet ...

  7. 使用ansible-galaxy部署角色

    使用ansible-galaxy部署角色 1. ansible galaxy的介绍 2. Ansible Galaxy命令的使用 2.1 使用Ansible Galaxy命令创建角色目录 2.2 使用 ...

  8. ansible 发部署nginx以及更新、回滚

    ansible 发部署nginx以及更新.回滚 ansible 和 saltstack 一样都是基于 Python 开发的,是比 puppet 和 saltstack 更轻量级的运维自动化工具. 一: ...

  9. Ansible中的角色使用

    ansible roles #ansible 角色简介# * Ansible roles 是为了层次化,结构化的组织Playbook * roles就是通过分别将变量.文件.任务.模块及处理器放置于单 ...

最新文章

  1. net core mysql 连接池_EF Core 小坑:DbContextPool 会引起数据库连接池连接耗尽
  2. Iphone 指触行为会
  3. Android okHttp上传图片
  4. 静态时序分析——单周期
  5. 网络编程-TCP/IP协议栈-UDP/HTTP协议
  6. 行为类模式(二):命令(Command)
  7. OGG迁移大库注意要点之impdp导入产生大量归档
  8. linux精灵进程之crond
  9. Oracle 单实例 迁移到 RAC 实例 -- 使用RMAN 异机恢复
  10. com.mysql.jdbc.connection和java.sql.connection的区别
  11. 个人计算机预防勒索病毒,避免电脑中勒索病毒的方法
  12. python爬取b站弹幕分析_Python爬取分析B站动漫《柯南》弹幕,从数据中分析接下来的剧情...
  13. emv交易流程介绍_(精)EMV流程介绍.ppt
  14. 华为ensp的路由器怎么和本地电脑通信
  15. Python实现遗传算法(GA)+支持向量回归机(SVR)
  16. [分享]方便的 windbg 命令 - !list
  17. 网络基础 - 网关、网段、子网掩码、DNS
  18. error: No rule to make target '/usr/lib/libOpenNI.so', needed by 'bin/euroc_rectify'。 停止。
  19. 金蝶BOS,界面区域按钮增加权限控制
  20. 北京内推 | 微软亚洲研究院DKI组招聘大模型方向研究实习生

热门文章

  1. python 抓取解析接口数据_[干货]用python抓取摩拜单车API数据并做可视化分析(源码)...
  2. 什么是MaxCompute
  3. KDevelop修改字体样式和大小
  4. linux tengine,Linux 安装 Tengine
  5. 基于IMM和UKF的三维路径预测跟踪matlab仿真,模型包括匀速模型CV,匀加速模型CA以及常速率协同转弯模型CSCT
  6. zenmate android apk,ZenMate - IP Browser Check 0.1.7
  7. 微信小程序开发实战10_1 小程序支付业务介绍
  8. 合并排序(归并排序)
  9. 春季行情“躁动” 量加在手“从容”
  10. Java俱乐部第三周练习题