[root@foundation50 .ansible]# vim ansible.cfg
[root@foundation50 .ansible]# mkdir /root/.ansible/roles 建立指定的目录
[root@foundation50 .ansible]# ansible-galaxy list 列出roles
[root@foundation50 .ansible]# cd /root/.ansible/roles/ 进入roles目录
[root@foundation50 roles]# ansible-galaxy init apache


[root@foundation50 apache]# cd vars/ 进入变量目录
[root@foundation50 vars]# vim main.yml 编辑文件

[root@foundation50 apache]# vim tasks/  进入tasks目录
[root@foundation50 tasks]# vim main.yml  编辑文件 ,不需要缩进1 ---2 # tasks file for apache3 - name: install apache4   dnf:5    name: httpd6    state: latest7 - name: config apache   都顶格写8   lineinfile:                                                               9     path: /etc/httpd/conf/httpd.conf10     regexp: "^Listen"11     line: "listen{{PORT}}"12   notify: restart apache13   changed_when: true14 15 - name: start apache  定格16   service:17     name: httpd18     state: started19     enabled: yes                                                          [root@foundation50 apache]# cd handlers/   进入触发器目录
[root@foundation50 handlers]# vim main.yml  编辑文件
---
# handlers file for apache
- name: restart apacheservice:name: httpdstate: restarted[root@foundation50 ~]# cd .ansible/
[root@foundation50 .ansible]# vim roles.yml
---
- name: test roleshosts: westosroles: - apache    如果有多个角色,依次在后面加
[root@foundation50 .ansible]# ansible-playbook  roles.yml  运行角色的作用:把playbook片段全部拆开,放到该方的位置,不会因为playbook过长而导致缩进出现问题 ,不需要缩进全是定格





[root@foundation50 .ansible]# ansible-galaxy collection install nginxinc.nginx_core  下载
[root@foundation50 .ansible]# cd collections/
[root@foundation50 collections]# ls
ansible_collections
[root@foundation50 collections]# cd ansible_collections/
[root@foundation50 ansible_collections]# ls
nginxinc
[root@foundation50 ansible_collections]# cd nginxinc/
[root@foundation50 nginxinc]# ls
nginx_core
[root@foundation50 nginxinc]# cd nginx_core/
[root@foundation50 nginx_core]# ls
CHANGELOG.md        docs        MANIFEST.json  plugins
CODE_OF_CONDUCT.md  FILES.json  meta           README.md
CONTRIBUTING.md     LICENSE     playbooks      roles
[root@foundation50 nginx_core]# cd roles/
[root@foundation50 roles]# ls
nginx  nginx_app_protect  nginx_config    nginx所有资源
[root@foundation50 roles]# cp -r * /root/.ansible/roles   将nginx资源复制到 /root/.ansible/roles 指定的角色目录里面
[root@foundation50 roles]# ls /root/.ansible/roles
apache  nginx  nginx_app_protect  nginx_config
[root@foundation50 roles]# ansible-galaxy list  列出角色
# /root/.ansible/roles
- apache, (unknown version)      nginx角色已经存在了
- nginx, (unknown version)
- nginx_app_protect, (unknown version)
- nginx_config, (unknown version)
# /usr/share/ansible/roles
# /etc/ansible/roles

安装自己的包

[root@foundation50 roles]# ls
apache  nginx  nginx_app_protect  nginx_config
[root@foundation50 roles]# tar zcf apache.tar.gz apache   打包apache
[root@foundation50 roles]# rm -fr apache
[root@foundation50 roles]# ls
apache.tar.gz  nginx  nginx_app_protect  nginx_config
[root@foundation50 ~]# cd .ansible/
[root@foundation50 .ansible]# ansible-galaxy list  没有apache角色
# /root/.ansible/roles
- nginx, (unknown version)
- nginx_app_protect, (unknown version)
- nginx_config, (unknown version)
[root@foundation50 .ansible]# mv apache.yml /mnt/   移动到/mnt里
[root@foundation50 .ansible]# vim install_role.yml
---
- src: file:///mnt/apache.tar.gz    压缩包的位置  ,此处源也可以是互联网地址name: westos   安装解压后的名字
[root@foundation50 .ansible]# ansible-galaxy install -r install_role.yml   安装
- downloading role from file:///mnt/apache.tar.gz
- extracting westos to /root/.ansible/roles/westos
- westos was installed successfully
[root@foundation50 roles]# ls
nginx  nginx_app_protect  nginx_config  westos  角色westos已经下载成功
[root@foundation50 roles]#

ansible中role角色的应用相关推荐

  1. ansible中的角色使用--nginx+持续交付和滚动升级+时间同步角色+selinux+自动添加磁盘

    文章目录 1. nginx 2. 持续交付和滚动升级 3. noarch(时间同步角色) 4. selinux 5.自动添加磁盘 使用角色添加磁盘 用任务命令创建lv 用任务命令进行设备分区 ansi ...

  2. Ansible中的角色使用

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

  3. The Role of Testers in an Agile Environment(测试人员在敏捷环境中的角色)

    目录 原链接 翻译内容 Summary(摘要): 正文 Confusion in the Literature(文献中的困惑) Tester as an Agile Team Member(测试员是敏 ...

  4. PostgreSQL数据库中的角色(Role)、用户(User)、模式(Schema)

    文章目录 PostgreSQL数据库中的角色(Role).用户(User).模式(Schema) 角色(Role)和用户(User) 角色操作 CREATE ROLE 创建角色 ALTER ROLE修 ...

  5. Ansible中的playbook详解

    首先简单说明一下playbook,playbook是什么呢? 根本上说playbook和shell脚本没有任何的区别,playbook就像shell一样,也是把一堆的命令组合起来,然后加入对应条件判断 ...

  6. ansible-playbook role角色

    文章目录 1. 介绍 2. 创建roles步骤 3. roles各目录中文件 4. 存储和查找角色 5. 使用角色 5.1 role 5.1.1 使用 allow_duplicates: true 5 ...

  7. ansible之playbook角色

    ansible之playbook&角色 playbook-剧本 简介 playbook组件用法 playbook变量 playbook语句 roles-角色 简介 用法 实战 playbook ...

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

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

  9. 使用ansible galaxy部署角色

    一,介绍ansible galaxy Ansible Galaxy [https://galaxy.ansible.com]是一个Ansible内容公共资源库,这些内容由许许多多Ansible管理员和 ...

最新文章

  1. OpenJDK官方正式宣布AWT、2D、Swing等项目解散
  2. mysql 让别人连接我的数据库
  3. visual studio 2008 html中调用外部css文件,的Visual Studio 2008 IDE冻结/崩溃打开.aspx文件中使用CSS时包括...
  4. Linux 下的格式化输出命令:print
  5. 40岁的程序员还能找到工作吗_如果程序员已经到三十岁了,那他还能找到满意的工作吗?...
  6. 2.3.4 mysql 用户密码管理
  7. 织梦cms第四版仿七猫技术导航源码 附安装教程
  8. ​多大分辨率图像做分类更适合?浙大华为国科大等提出Dynamic Resolution Network,降低计算量还提性能!...
  9. web前端入门到实战:CSS3两大实用属性,以及网页制作技巧
  10. 如何下载HLS视频到本地(m3u8)
  11. 超级全面的MySQL优化面试解析
  12. C语言学习7:ASCII码表及用法简介
  13. Python—Django中的视图(views.py)
  14. 考研计算机专业流程,计算机专业考研复试基本流程-文都教育.doc
  15. 系统命令联网激活方法
  16. 极客时间左耳听风-高效学习
  17. android 如何刷机,安卓怎么刷机_安卓刷机图解_刷机大师教程
  18. jmeter JSR223 PostProcessor 操作
  19. 全国计算机软考程序员考试大纲
  20. VS2013在MFC中使用ADO方法操作Access2013数据库

热门文章

  1. 详解core dump
  2. 网络工程师待遇、就业前景和职业规划
  3. python版我的世界怎么去天堂_minecraft我的世界手机版怎么去天堂教程
  4. ViewPager2+Fragment操作笔记
  5. JQuery printarea 打印空白问题解决
  6. 计算机一级b在线模拟,计算机一级B模拟试题.doc
  7. Rancher2忘记admin登录密码
  8. IMU的坐标系和初始化
  9. linux的tomcat下载,tomcat linux 64位下载
  10. android视频实时编辑器,安卓手机视频编辑器 (音乐相册、视频压缩、倒放、视频转MP3、视频剪切等)...