Teng's blog Teng's blog
首页
Java
H5前端
GitHub (opens new window)
首页
Java
H5前端
GitHub (opens new window)
  • 背景介绍
  • 安装
  • 配置说明
  • 基础命令
  • 常用模块
  • Playbook

    • 简单介绍
    • yaml语法
    • hosts
    • task
    • 运行playbook
    • handlers
    • tags
    • variables
    • template
    • when条件判断
    • with_items迭代
    • roles
    • 附:jinja2语法
  • Tool-Ansible
  • Playbook
Shetengteng
2022-05-13

tags

指定某条任务执行,用于选择运行playbook中的部分代码 ansible具有幂等性,因此会自动跳过没有变化的部分,即便如此,有些代码为测试其确实没有发生变化的时间依然会非常地长 如果确信其没有变化,就可以通过tags跳过此些代码片断

执行命令

ansible-playbook -t tagsname useradd.yml
1

示例:添加标签

  • 指定某一个任务添加一个标签,添加标签以后,想执行某个动作可以做出挑选来执行
  • 多个动作可以使用同一个标签
- hosts: websrvs
  remote_user: root
  
  tasks:
    - name: Install httpd
      yum: name=httpd state=present
      tage: install 
    - name: Install configure file
      copy: src=files/httpd.conf dest=/etc/httpd/conf/
      tags: conf
    - name: start httpd service
      tags: service
      service: name=httpd state=started enabled=yes


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  • 执行:指定执行install,conf 两个标签内的action
ansible-playbook –t install,conf httpd.yml   
1

示例:httpd2.yml

- hosts: testsrv
  remote_user: root
  tags: inshttpd   # 针对整个playbook添加tage
  tasks:
    - name: Install httpd
      yum: name=httpd state=present
    - name: Install configure file
      copy: src=files/httpd.conf dest=/etc/httpd/conf/
      tags: rshttpd
      notify: restart httpd
  handlers:
    - name: restart httpd
      service: name=httpd status=restarted
1
2
3
4
5
6
7
8
9
10
11
12
13
  • 执行
ansible-playbook –t rshttpd httpd2.yml
1
Last Updated: 2022/05/22, 12:42:00
handlers
variables

← handlers variables→

Theme by Vdoing | Copyright © 2021-2022 Shetengteng | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式