#理解
changed_when
failed_when
become
become_user
ansible_become
ansible_become_user
static #检查group_vars中某组是否存在主机
- name: ensure only one monitoring host exists
fail: msg="One, or no monitoring host may be specified."
when: "groups.get('monitoring_servers', [])|length > 1" #如果不定义值,那么使用默认值
- name: set deploy dir if not presented
set_fact: deploy_dir="/home/{{deploy_user}}/deploy"
when: deploy_dir is not defined #禁掉swap
- name: disable swap
shell: "([ $(swapon -s | wc -l) -ge 1 ] && (swapoff -a && echo disable)) || echo already"
ignore_errors: yes
register: swapoff_result
changed_when: "swapoff_result.stdout.strip() == 'disable'" #当set_timezone定义,设置相应时区
- name: set timezone to {{timezone}}
timezone: name={{ timezone }}
when: set_timezone #设置hostname
- name: set hostname by ip
hostname: name=ip-{{ ansible_default_ipv4.address | replace(".","-") }}
register: hostname_set
when:
- set_hostname
- "ansible_default_ipv4.address | replace('.','-') not in ansible_hostname" #设置/etc/hosts
- name: inject hostname to hosts file
lineinfile: dest=/etc/hosts line='127.0.0.1 ip-{{ ansible_default_ipv4.address | replace(\".\",\"-\") }}'
when: set_hostname '#修改文件中匹配到的某行
- name:modify centos irqbalance configuration file
lineinfile:
dest=/etc/default/irqbalance
regexp='(?<!_)ONESHOT='
line='ONESHOT=yes'
when:
- tuning_irqbalance_value
- centos_irq_config_file.stat.exists #检查umask
- name: get umask
shell: umask
register: umask
changed_when: False - name: does the system have a standard umask
fail: 'The umask of the system ({{ umask.stdout.strip() }}) prevents successful installation. We suggest a standard umask such as 0022.'
when: umask.stdout.strip()[-:] not in ('', '', '', '') #根据facts值,检查系统版本
- name: check system version
fail:
msg: "Red Hat Enterprise Linux/CentOS 6 is deprecated"
when: "ansible_os_family == 'RedHat' and ansible_distribution_major_version == '6" #检查文件挂载点
- name: detemine which mountpoint depoly dir exists on
shell: "df {{ deploy_dir }} | tail -n1 | awk '{print $NF}'"
register: deploy_partition
changed_when: False #抓取log
- name: fetch pd log file
fetch:
src: "{{ log_dir }}/{{ inventory_hostname }}-pd.tar.gz"
dest: "{{ fetch_tmp_dir }}/{{ inventory_hostname }}/"
flat: yes
validate_checksum: no
when: "'pd_servers' in group_names" #下载tidb二进制
- name: download tidb binary
get_url:
url: "{{ item.url }}"
dest: "{{ doenloads_dir }}/{{ item.name }}-{{ item.version }}.tar.gz"
checksum: "{{ item.checksum | default(omit) }}"
force: yes
validate_certs: no
register: get_url_result
until: "'OK' in get_url_result.msg or 'file already exists' in get_url_result.msg"
retries:
delay: "{{ retry_stagger | random + 3 }}"
with_items: "{{ tidb_packages }}"
when: has_outband_network #debug
- debug:
msg: "run command on server: {{ disk_randread_iops.cmd }}"

ansible roles例子的更多相关文章

  1. ansible roles 目录规范

    我的ansible roles项目的目录结构: (ansible_venv) [root@localhost ansible_home]# tree ansible_playbooks/ ansibl ...

  2. 6.Ansible Roles角色实战

    ==Roles小技巧:== 1.创建roles目录结构,手动或使用ansible-galaxy init test roles 2.编写roles的功能,也就是tasks. nginx rsyncd ...

  3. Ansible--06 ansible roles

    Ansible roles roles不管是Ansible还是saltstack,我在写一键部署的时候,都不可能把所有的步骤全部写入到一个'剧本'文件当中,我们肯定需要把不同的工作模块,拆分开来,解耦 ...

  4. ansible roles 自动化安装

    例:  ansible roles 自动化安装memcached 文件目录结构如下: cat memcached_role.yml - hosts: memcached remote_user: ro ...

  5. ansible roles实践——安装nginx

    1.创建roles 在/etc/ansible/roles目录下 1.1 手动创建需要的目录 1.2 使用命令创建,用不到的目录可以创建为空目录,但不可以不创建. 创建目录[root@master] ...

  6. ansible实用例子

    寻找/etc/ 名为"hosts" 递归查找 ansible webserver -m find -a ' path=/etc/ file_type=any recurse=yes ...

  7. Ansible Roles角色

    Roles小技巧: 1.创建roles目录结构,手动或使用ansible-galaxy init test roles 2.编写roles的功能,也就是tasks. nginx rsyncd memc ...

  8. ansible roles 介绍和使用

    目录 roles roles 介绍 创建role的步骤 role内个目录中可用的文件 案例 roles roles 介绍 ansible 自1.2版本引入的新特性,用于层次性.结构化地组织playbo ...

  9. ansible roles实践 zookeeper集群部署

    1.下载解压 wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11. ...

随机推荐

  1. debian下使用dpkg来安装/卸载deb包 (转载)

    转自:http://blog.csdn.net/zhou_2008/article/details/6076900 在debian下,你可以使用dpkg(Debian package system)来 ...

  2. 使用Advanced Installer14.3 简单打包windows窗体应用程序

    1.新建项目工程(我使用的是企业版) 2.完善产品细节 3.应用程序文件夹 a.自动同步文件夹(也可以右键添加文件或文件夹) b.新建卸载快捷方式 c.卸载清理 4.安装参数 5.媒介配置 6.生成或 ...

  3. MySQL基础 — 常用命令

    一.连接MySQL 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MySQ: 首先在打开cmd窗口,输入mysql -uroot -p ,然后空格进入MySQL控制台, ...

  4. nginx 多进程 + io多路复用 实现高并发

    一.nginx 高并发原理 简单介绍:nginx 采用的是多进程(单线程) + io多路复用(epoll)模型 实现高并发 二.nginx 多进程 启动nginx 解析初始化配置文件后会 创建(for ...

  5. Quartz定时调度jar包的执行Demo分享

    1.Quartz简介 ​ Quartz框架的核心是调度器.调度器负责管理Quartz应用运行时环境.调度器不是靠自己做所有的工作,而是依赖框架内一些非常重要的部件.Quartz不仅仅是线程和线程管理. ...

  6. ROS-USB摄像头

    前言:演示使用usb摄像头功能,推荐使用方法二. 首先要有一个usb摄像头,本次使用的是罗技(Logitech)摄像头. 一.使用软件库里的uvc-camera功能包 1.1 检查摄像头 lsusb ...

  7. ZOJ-3960 What Kind of Friends Are You?

    What Kind of Friends Are You? Time Limit: 1 Second      Memory Limit: 65536 KB Japari Park is a larg ...

  8. .Net MVC之间的关系以及如何运用

    .Net MVC组成部分:视图(views)模型(model)控制器(controller)以及路由(RouteConfig),视图跟模型的数据不进行直接的交互,他们是通过控制器进行视图模型之间的数据 ...

  9. 手机页面操作栏的创建及WebFont的使用

    一.手机界面底部操作栏的创建. <style> .opers{ position:absolute; bottom:0px; left:0px; right:0px; height:3re ...

  10. Activity的退出和進入效果

    看了android的源代码和资源文件,终于明白如何去修改设置Dialog和Activity的进入和退出效果了.设置Dialog首先通过 getWindow()方法获取它的窗口,然后通过getAttri ...