#理解
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. CentOS下网卡启动、配置等ifcfg-eth0教程

    步骤1.配置/etc/sysconfig/network-scripts/ifcfg-eth0 里的文件. CentOS6.4 下的ifcfg-eth0的配置详情: [root@Jeffery]# v ...

  2. 分布式事务(三)mysql对XA协议的支持

    系列目录 分布式事务(一)原理概览 分布式事务(二)JTA规范 分布式事务(三)mysql对XA协议的支持 分布式事务(四)简单样例 分布式事务(五)源码详解 分布式事务(六)总结提高 引子 从Mys ...

  3. mysql的子查询的提高

    统计胜负结果的sql语句 date                       result 2011-02-01          胜 2011-02-01          负 2011-02-0 ...

  4. JS 实现PDF文件打印

    function PdfPrint() {        bdhtml = window.document.body.innerHTML;        sprnstr = "<!-- ...

  5. Windows环境下使用Netsh命令快速切换IP配置

    不同的内网环境需要使用不同的IP配置,频繁切换令人发狂,因此搜索了快速切换IP配置的方法. Netsh interface IP Set address "以太网" Static ...

  6. 数据传递-------@ResponseBody

    1.导入jar包 jack-core-asl-1.9.11.jar jack-mapper-asl-1.9.11.jar 2.配置springmvc-servlet.xml文件 <?xml ve ...

  7. JSP/Servlet Web应用中.properties文件的放置与读取

    本地项目 在本地类库中,我经常使用当前目录来放置.properties文件,这时调用方只要引用我的jar,并且将我的.properties放在他的classpath里面即可,比如: p.load(ne ...

  8. Android 将Bitmap对象保存为png图片文件

    输入:Bitmap对象.保存的路径.保存的文件名 注意路径的最后要带上  '/' 符号 private void saveBitmap(Bitmap bitmap,String path, Strin ...

  9. Zynq7000系列之芯片引脚功能综述

    很多人做了很久的FPGA,知道怎么去给信号分配引脚,却对这些引脚的功能及其资源限制知之甚少:在第一章里对Zynq7000系列的系统框架进行了分析和论述,对Zynq7000系列的基本资源和概念有了大致的 ...

  10. java虚拟机(三)--HotSpot 对象

    普通对象的创建(不包括数组和class对象): 当虚拟机遇到new指令时,会在常量池中检查是否包含这个类的符号引用(全限定名),通过这个确定是否经过类加载的过程,如果true,为该 对象分配内存,对象 ...