访次: AmazingCounters.com 次

ansible-playbook之include结合tags的使用

ansible-playbook之include结合tags的使用

此playbook的作用:通过指定标签(tags),来说明是安装tomcat7还是tomcat8

main.yml:

---
- include: install_tomcat7.yml
  tags: tomcat7
- include: install_tomcat8.yml
  tags: tomcat8

install_tomcat7.yml:

复制代码
---
- name: "复制文件到远程主机"
  copy:
    src={{ item.src }}
    dest={{ item.dest }}
  with_items:
    - src: jdk-7u79-linux-x64.rpm
      dest: /usr/local/src/
    - src: java17.sh
      dest: /etc/profile.d/
- name: "安装jdk"
  yum:
    name: /usr/local/src/jdk-7u79-linux-x64.rpm
    state: present
- name: "重新加载环境变量"
  shell: "source /etc/profile.d/java17.sh"
- name: "复制tomcat文件到远程服务器并解压"
  unarchive:
    src=apache-tomcat-7.0.64.zip
    dest=/data/
    copy=yes
    owner=staplesapp
    group=admin
- name: "对解压后的文件重命名"
  shell: mv /data/apache-tomcat-7.0.64 /data/tomcat7
- name: "对tomcat进行相关配置"
  shell: find /data/tomcat7/bin -name "*.sh" | xargs chmod +x
- name: "启动tomcat"
  shell: 'nohup /data/tomcat7/bin/startup.sh &'
复制代码

install_tomcat8.yml:

复制代码
---
- name: "复制文件到远程主机"
  copy:
    src={{ item.src }}
    dest={{ item.dest }}
  with_items:
    - src: jdk-8u111-linux-x64.rpm
      dest: /usr/local/src/
    - src: java18.sh
      dest: /etc/profile.d/
- name: "安装jdk"
  yum:
    name: /usr/local/src/jdk-8u111-linux-x64.rpm
    state: present
- name: "配置java环境变量"
  shell: "source /etc/profile.d/java18.sh"
- name: "安装tomcat"
  unarchive:
      src=apache-tomcat-8.0.30.tar.gz
      dest=/data/
      copy=yes
      owner=staplesapp
      group=admin
- name: "对解压后的文件重命名"
  shell: mv /data/apache-tomcat-8.0.30 /data/tomcat8
- name: "启动tomcat"
  shell: 'nohup /data/tomcat8/bin/startup.sh &'
复制代码

安装tomcat7:ansible-playbook tomcat.yml --tags tomcat7

安装tomcat8:ansible-playbook tomcat.yml --tags tomcat8

 注:在早先版本使用 include 整合多个roles至统一入口结合tags 标签来管理roles 剧本,但在 2.8 版本之后将会删除 include语法,更改我为import_playbook

例如:

---
- include: test.yml
  tags: test
- include: twsdyxz.web.yml
  tags: twsdyxz
#2.8版本之前可以这样写,但是会有警告 [DEPRECATION WARNING]:'include' for playbook includes. You should use 'import_playbook' instead. This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

使用:import_playbook

- import_playbook: test.yml
  tags: test
- import_playbook: twsdyxz.web.yml
  tags: twsdyxz

 

posted @   IT老登  阅读(1346)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
访次: AmazingCounters.com 次
点击右上角即可分享
微信分享提示