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. ...
随机推荐
- CodeForces 124C Prime Permutation (数论+贪心)
题意:给定一个字符串,问你能不能通过重排,使得任意一个素数p <= 字符串长度n,并且 任意的 i <= 长度n/素数p,满足s[p] == s[p*i]. 析:很容易能够看出来,只要是某 ...
- Hibernate的表之间的关系
表:A.B 一对多关系:A中的一个字段的记录(主键)引用B中的多个记录(外键) 多对一关系:A中的一个字段的记录(外键)引用B中的一个记录(主键) 一对一关系:A.B两个表的关联字段都是主键 多对多关 ...
- bzoj 1684: [Usaco2005 Oct]Close Encounter【数学(?)】
枚举分母,然后离他最近的分子只有两个,分别判断一下能不能用来更新答案即可 #include<iostream> #include<cstdio> #include<cma ...
- 为什么Markdown能夺得程序员的青睐
Markdown基本情况概述 Markdown是在HTML的基础上产生的.HTML的功能已经足够强大,可以编写出漂亮的网页.HTML在没有CSS的加持上,尽管不能显示出绚丽多彩的网页,但是仍然可以达到 ...
- 源码阅读之HashMap(JDK8)
概述 HashMap根据键的hashCode值存储数据,大多数情况下可以直接定位到它的值,因而具有很快的访问速度,但遍历顺序却是不确定的. HashMap最多只允许一条记录的键为null,允许多条记录 ...
- 公司5:JrVue表格
组件名称:jr-dynamic-query-table 组件布局 table组件名称: jr-dynamic-query-table 分页组件名称: el-pagination <div re ...
- 生成 Guid
//生成Guid function getGuidGenerator() { var S4 = function () { return (((1 + Mat ...
- ASP.NET 简介(转自Wiki)
ASP.NET是由微软在.NET Framework框架中所提供,开发Web应用程序的类库,封装在System.Web.dll文件中,显露出System.Web名字空间,并提供ASP.NET网页处理. ...
- ASP.NET GridView 控件绑定 CheckBoxList
需求:设计这样一个页面,在页面上可以自由选择和展示各省份下城市? 思路:一次性查询出所需的记录(查询数据库的操作不宜写到 C# 代码的循环语句中),并保存到全局变量中,之后根据条件过滤出需要的.可以在 ...
- 喜欢Swift编程语言的人主要是初学者?
一早一起来,朋友圈除了被苹果发布会刷屏外,还漫天散布着一条类似的招聘消息:“招聘iOS程序员,要求拥有5年的Swift开发经验,有狼性,待遇月薪20K+,专车接送.” 随后身边的朋友很快就开始调侃:& ...