ansible roles例子
#理解
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例子的更多相关文章
- ansible roles 目录规范
我的ansible roles项目的目录结构: (ansible_venv) [root@localhost ansible_home]# tree ansible_playbooks/ ansibl ...
- 6.Ansible Roles角色实战
==Roles小技巧:== 1.创建roles目录结构,手动或使用ansible-galaxy init test roles 2.编写roles的功能,也就是tasks. nginx rsyncd ...
- Ansible--06 ansible roles
Ansible roles roles不管是Ansible还是saltstack,我在写一键部署的时候,都不可能把所有的步骤全部写入到一个'剧本'文件当中,我们肯定需要把不同的工作模块,拆分开来,解耦 ...
- ansible roles 自动化安装
例: ansible roles 自动化安装memcached 文件目录结构如下: cat memcached_role.yml - hosts: memcached remote_user: ro ...
- ansible roles实践——安装nginx
1.创建roles 在/etc/ansible/roles目录下 1.1 手动创建需要的目录 1.2 使用命令创建,用不到的目录可以创建为空目录,但不可以不创建. 创建目录[root@master] ...
- ansible实用例子
寻找/etc/ 名为"hosts" 递归查找 ansible webserver -m find -a ' path=/etc/ file_type=any recurse=yes ...
- Ansible Roles角色
Roles小技巧: 1.创建roles目录结构,手动或使用ansible-galaxy init test roles 2.编写roles的功能,也就是tasks. nginx rsyncd memc ...
- ansible roles 介绍和使用
目录 roles roles 介绍 创建role的步骤 role内个目录中可用的文件 案例 roles roles 介绍 ansible 自1.2版本引入的新特性,用于层次性.结构化地组织playbo ...
- ansible roles实践 zookeeper集群部署
1.下载解压 wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11. ...
随机推荐
- "git rm" 和 "rm" 的区别(转载)
转自:http://yang3wei.github.io/blog/2013/02/03/git-rm-he-rm-de-qu-bie/ 这是一个比较肤浅的问题,但对于 git 初学者来说,还是有必要 ...
- 台哥原创:java 连连看源码
2010年,迷上了玩连连看 随手就做了这个,正好手头有这些图片素材 游戏启动时,界面先铺上了一层透明幕布,然后这些兵器图片交替从上到下,从左到右出现.. 鼠标停在兵器格子上时,所在格子会有红色 ...
- spring 简单实现BeanFactory(转)
原文地址: http://blog.csdn.net/mlc1218559742/article/details/52776160 有没有发现上面的代码与利用反射实现工厂模式的代码很相似.对,你没有看 ...
- 51nod1265判断四点共面
1265 四点共面 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出三维空间上的四个点(点与点的位置均不相同),判断这4个点是否在同一个平面内(4点共 ...
- 全面学习ORACLE Scheduler特性(2)管理jobs
1.2 管理Jobs 1.2.1 启用Jobs 前面创建JOB时,由于未显式的指定ENABLED参数,因此即使指定了START_DATE,不过默认情况下JOB不会自动执行.对于这种情况,DBMS_ ...
- 391 Perfect Rectangle 完美矩形
有 N 个与坐标轴对齐的矩形, 其中 N > 0, 判断它们是否能精确地覆盖一个矩形区域.每个矩形用左下角的点和右上角的点的坐标来表示.例如, 一个单位正方形可以表示为 [1,1,2,2]. ( ...
- DateFormat 多线程问题
在写实时应用解析日志的时候,有如下代码: public class CalPvLogParse { private static SimpleDateFormat logTimeFormat = ne ...
- Appium环境部署
Appium 是一个开源.跨平台的自动化测试工具,用于测试原生和轻量移动应用,支持 iOS, Android平台. 需要部署的软件:python环境.nodejs..net framework4.5. ...
- Android开发笔记(2)——ViewGroup
笔记链接:http://www.cnblogs.com/igoslly/p/6794344.html 一.ViewGroup 1.ViewGroup的意义——整合Layout多个不同View,并对其进 ...
- (转) 淘淘商城系列——redis-desktop-manager的使用
http://blog.csdn.net/yerenyuan_pku/article/details/72849791 实际工作环境中,redis会安装在服务器上,我们想使用redis服务就要使用re ...