playbook

setup

ansible_all_ipv4_addresses # ipv4的所有地址
ansible_all_ipv6_addresses # ipv6的所有地址
ansible_date_time # 获取到控制节点时间
ansible_default_ipv4 # 默认的ipv4地址
ansible_distribution # 系统
ansible_distribution_major_version # 系统的大版本
ansible_distribution_version # 系统的版本号
ansible_domain #系统所在的域
ansible_env #系统的环境变量
ansible_hostname #系统的主机名
ansible_fqdn #系统的全名
ansible_machine #系统的架构
ansible_memory_mb #系统的内存信息
ansible_os_family # 系统的家族
ansible_pkg_mgr # 系统的包管理工具
ansible_processor_cores #系统的cpu的核数(每颗)
ansible_processor_count #系统cpu的颗数
ansible_processor_vcpus #系统cpu的总个数=cpu的颗数*CPU的核数
ansible_python # 系统上的python
ansible cache -m setup -a 'filter=*processor*' # 用来搜索

* 匹配数量,表示0或者多次

? 匹配数量,表示0或者1次

. 除换行符以外的所有字符

+ 至少一次

[123abc] 匹配内容,or

() 分组

{m} 次数,出现m次

{m,} 至少m次

{m,n}出现m-n次

a*.b

- hosts: db
tasks:
- name: zzgbgn
dong: zzdbgn
when: zhanzhe
- name: pzhegbgn
dong: pzhedbgn
when: pazhe

条件判断

  • 不同的系统

  • 不同的版本

  • 不同的环境

  • 不同的用户

- hosts: db
remote_user: root # 用来执行的用户 默认是root
tasks:
- name: createfile
copy: content="大弦嘈嘈如急雨" dest=/tmp/a.txt
when: a==""
- name: cratefile
copy: content="小弦切切如私语" dest=/tmp/a.txt
when: a==""

Ubuntu 安装包的方式是apt-get

tags

- hosts: db
tasks:
- name: wadong
tieqiao: wadong
- name: tk
dong: tk
tags: tk
- hosts: web
tasks:
- name: installnginx
yum: name=nginx
- name: copyfile
copy: src=/etc/nginx/nginx.conf dest=/etc/nginx/nginx.conf
tags: copyfile
- name: start
service: name=nginx state=started ansible-playbook -t copyfile p7.yml

循环 with_item

一次性创建多个

- hosts: gb
tasks:
- name: gbqc
dong: {{ item }}
with_items:
- qbqc
- cyf
- ssfj - hosts: web
tasks:
- name: crateuser
user: name={{item}}
with_items:
- alex20
- alex21
- alex22
~
- hosts: web
tasks:
- name: crateuser
user: name={{item}}
with_items:
- alex30
- alex31
- alex32
- name: crategroup
group: name={{item}}
with_items:
- wulaoshi20
- wulaoshi21
- wulaoshi22
~    

嵌套循环

- hosts: web
tasks:
- name: crategroup
group: name={{item}}
with_items:
- wulaoshi30
- wulaoshi31
- wulaoshi32
- name: createuser
user: name={{item.name}} group={{item.group}}
with_items:
- {'name':alex40,'group':wulaoshi30}
- {'name':alex41,'group':wulaoshi31}
- {'name':alex42,'group':wulaoshi32}

template:

jinja2 后缀名一般为j2

- hosts: web
tasks:
- name: installredis
yum: name=redis
- name: copyfile
template: src=/etc/redis.conf dest=/etc/redis.conf
- name: start
service: name=redis state=started
配置文件: bind {{ ansible_default_ipv4.address }}

copy和tamplate的区别

  • copy模块不替代参数

  • template模块替代参数

- hosts: web
tasks:
- name: installredis
yum: name=redis
- name: copyfile
template: src=redis.conf dest=/etc/redis.conf
- name: start
service: name=redis state=started

ps:写相对路径: 在当前目录下新建一个templates目录,然后把文件放在templates目录里面

handlers

修改配置文件

- hosts: web
tasks:
- name: installredis
yum: name=redis
- name: copyfile
template: src=redis.conf dest=/etc/redis.conf
tags: copyfile
notify: restart
- name: start
service: name=redis state=started
handlers:
- name: restart
service: name=redis state=restarted

回顾 playbook

传参

条件判断 when

循环 with_items item

嵌套循环 字典 通过点来取值

标签 tags -t 来传递标签

模板 template

handlers 不会执行, notify

roles

  • 目录清晰

  • 可以互相调用

roles文件夹

文件夹里面是要创建的每一个角色,每一个角色一个文件夹

每一个角色里面都有tasks(必须的),templates,files,handlers,vars目录

每个目录都要有main.yml文件,通过import_tasks来调用

其中templates文件夹中的文件可以通过相对路径来调用

其中files文件夹中的文件是否可以通过相对路径来调用?

mysql my

mariadb

Hadoop 大数据

setenforce 0 #用来临时关闭selinux
iptables -F # 临时关闭防火墙
/etc/selinux/config # 永久关闭

yum install -y ntp # 安装时间有关的
ntpdate time.windows.com # 调整时间
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime # 修改为中国上海时间
date #查看时间

最新文章

  1. 观点:BPM已经过时了?
  2. nodejs初窥
  3. 20145215《Java程序设计》第6周学习总结
  4. Cookie的使用与实现记住用户名案例
  5. Nginx 笔记与总结(8)Location:归纳总结
  6. MFC获取文本框字符串
  7. C++ 中 int,char*,string,CString之间相互转换-整理
  8. Calling Lua From a C Program
  9. Windows平台上C++开发内存泄漏检查方法
  10. cli下的php(并传递参数)
  11. OpenCms创建站点过程图解——献给OpenCms的刚開始学习的人们
  12. 面试的妹纸问我:web缓存设置不是后台的事情吗?
  13. 一致性hash算法以及其在分布式系统中的应用(转)
  14. 内存压测工具Memtester
  15. 发布到FaceBook试玩广告,FaceBook要求要一个Html文件
  16. 忽略SIGPIPE信号
  17. How to write threats to validity?
  18. Arduino开发版学习计划--蓝牙控制小车行走
  19. Maven聚合模式
  20. CSU1030素数槽

热门文章

  1. echarts图标legend全选功能添加
  2. swift基础语法之——变量和常量
  3. redis启动后出现"WARNING you have Transparent Huge Pages (THP) support enabled in your kernel"问题
  4. [Ruby]转载: 关于ruby中 %Q, %q, %W, %w, %x, %r, %s 的用法
  5. org.json里实现XML和JSON之间对象互转
  6. java 柱状图、折线图、饼状图
  7. JQuery判断页面是否按下了Enter键
  8. 本地访问Vmware虚机Web网站
  9. 用异或运算交换两个整数实现swap函数功能
  10. linux 数据库管理