ansible 剧本进阶 角色
主要内容:
playbook(剧本)
roles
一.查看收集到的信息
ansible cache -m setup
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
remote_user: 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
redis安装
- 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 # 永久关闭
用roles 来安装nginx+uwsgi+mariadb + redis
ansible 剧本进阶 角色的更多相关文章
- 自动化运维工具——ansible剧本playbook(三)
一.Playbook--Ansible剧本 playbook是由一个或多个 "play"组成的列表 play的主要功能在于将事先归并为一组的主机装扮成事先通过ansible中的ta ...
- Git+Gitlab+Ansible剧本实现一键部署动态网站(二)--技术流ken
项目前言 之前已经写了一篇关于git和ansible的博客<Git+Gitlab+Ansible剧本实现一键部署Nginx--技术流ken>.关于git,gitliab,ansible在我 ...
- Ansible剧本介绍及使用演示(week5_day2)--技术流ken
Ansible剧本编写说明 一. 缩进 yaml 的缩进要求比较严格.一定不能使用tab键 注意:编写yaml文件,就忘掉shell的tab吧. 二. 冒号 每个冒号后面一定要有一个空格 注意:1. ...
- ansible剧本之playbook操作
ansible 剧本 yaml介绍: 是一个编程语言 文件后缀名 yaml yml 数据对应格式: 字典: key: value 列表: [] - ansible-playbook命令格式 执行顺序: ...
- Git+Gitlab+Ansible剧本实现一键部署动态网站(5)
项目前言 之前已经写了一篇关于git和ansible的博客<Git+Gitlab+Ansible剧本实现一键部署Nginx–技术流ken>.关于git,gitliab,ansible在我以 ...
- Ansible剧本介绍及使用演示(3)
Ansible剧本编写说明 一. 缩进 yaml 的缩进要求比较严格.一定不能使用tab键 注意:编写yaml文件,就忘掉shell的tab吧. 二. 冒号 每个冒号后面一定要有一个空格 注意:1. ...
- Ansible_使用Ansible galaxy部署角色
一.介绍Anisble galaxy 1.介绍Ansibleu galaxy 1️⃣:Ansible Galaxy (官网:https://galaxy.ansible.com)是一个Ansible内 ...
- ansible 剧本
ansible的管理与剧本 首先我们安装一个ansible. 在7版本,直接用yum安装就可以 yum -y install ansible 然后清空ansible的配置文件,在里面写入自己需要管 ...
- CentOS 6.5环境使用ansible剧本自动化部署Corosync + pacemaker环境及corosync常用配置详解
环境说明: 192.168.8.39 node2.chinasoft.com 192.168.8.42 node4.chinasoft.com 192.168.8.40 ansible管理服务器 19 ...
随机推荐
- React前端有钱途吗?《React+Redux前端开发实战》学起来
再不学React就真的跟不上大前端的形式了,目前几乎所有前端的招聘条件都是精通React者优先,看看拉勾网的React薪资,都是15K-20K,这个暑假,必须动起来了. 如果你熟悉JavaScript ...
- Vue项目里添加特殊字体或 某些字体乱码的问题
问题:有个西藏的项目因使用藏文,而出现乱码 (一开始不乱的,不知道后台怎么处理...后来不知道为啥,前端乱码了) 解决:字体ttf 格式已下载,在项目中全局引入了 @font-face { font- ...
- wampserver2.2 在window2003下的安装的主要问题
准备安装最新的wampserver 2.2c, 1.安装问题,安装完成后总是无法启动服务 系统事件中提示错误 找不到附属汇编 Microsoft.VC90.CRT,上一个错误是 参照的汇编没有 ...
- Linux编译阻塞型驱动遇到'TASK_NORMAL' undeclared (first use in this function)问题解决办法
http://blog.csdn.net/qq_16405157/article/details/49281793
- DOS批处理中%~dp0等扩充变量语法详解
有时候我们看到别人使用%~dp0 ~是扩展的意思,相当于把一个相对路径转换绝对路径%0代指批处理文件自身%1表示批处理文件命令行接收到的第一个参数,%2表示第二个,以此类推%~d0 是指批处理所在的盘 ...
- label smooth
图像分类的一个trick,推导可参考这位博主https://leimao.github.io/blog/Label-Smoothing/ 知乎上的讨论https://www.zhihu.com/que ...
- 防sql注入方法
mysql_escape_string(strip_tags($arr)) /** * 函数名称:post_check() * 函数作用:对提交的编辑内容进行处理 * 参 数:$post: 要提交的内 ...
- qt中不能编辑
下载的qt代码不能编辑,原因是文本编码是GB2312,现在选择的是utf-8,把编码改过来就可以编辑了
- python+Appium自动化:logging配置代码分离
配置文件信息log.conf: [loggers]keys=root,simpleExample [logger_root]level=DEBUGhandlers=consoleHandler,fil ...
- p1364 医院设置 题解
思路:floyd 很普通的思路. 先用floyd求出两个边之间的距离,然后乘以人数. 代码: #include<iostream> #include<cstring> usin ...