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 #查看时间

playbook+roles的更多相关文章

  1. Ansible playbook roles

    1  概述 角色(roles):如果我们使用playbook写成一个文件,这个文件会很大,但是不方便组织,我们可以分组,把playbook根据功能,如handler,tasks等分门别类的放在在各自的 ...

  2. devops工具-Ansible进阶playbook&roles

    一.playbook介绍     playbook 是 Ansible 管理配置.部署应用的核心所在,一个playbook由有多“play组成”,而一个play实际就是一个task,每个task是由多 ...

  3. Ansible Playbook Roles and Include Statements

    介绍 虽然可以在一个非常大的文件中编写一个playbook(您可能会以这种方式开始学习playbook),但最终您将需要重新使用文件并开始组织事情. 在基本级别,饱含任务的文件允许您将配置策略分解成较 ...

  4. ansible playbook最佳实践

    本篇主要是根据官方翻译而来,从而使简单的翻译,并没有相关的实验步骤,以后文章会补充为实验步骤,此篇主要是相关理论的说明,可以称之为中文手册之一,具体内容如下: Ansible playbooks最佳实 ...

  5. ansible-playbook && Roles && include

    先看一个yml文件示例 --- - hosts: webservers #主机组 vars: ##变量设置 http_port: 80 max_clients: 200 remote_user: ro ...

  6. ansible安装配置及最佳实践roles

    ansible是什么? ansible是一款轻量级配置管理工具,用于远程批量部署.安装.配置.类似的还有puppet.saltstack,各有所长,任君自选. 官方文档:http://docs.ans ...

  7. ansible roles 目录规范

    我的ansible roles项目的目录结构: (ansible_venv) [root@localhost ansible_home]# tree ansible_playbooks/ ansibl ...

  8. Ansible学习记录五:PlayBook学习

    0.介绍 Playbooks 是 Ansible 管理配置.部署应用和编排的语言,可以使用 Playbooks 来描述你想在远程主机执行的策略或者执行的一组步骤过程等 类似于一组任务集,定义好像项目, ...

  9. Ansible批量自动化管理工具 roles标准化

    批量管理服务器的工具,无需部署代理,通过ssh进行管理,是python写的 ansible 常用模块 : (1)shell命令模块执行命令 (2)copy模块批量下发文件或文件夹 (3)script模 ...

随机推荐

  1. [51nod1220] 约数之和(杜教筛+莫比乌斯反演)

    题面 传送门 题解 嗯--还是懒得写了--这里 //minamoto #include<bits/stdc++.h> #define R register #define IT map&l ...

  2. 转载《centos6安装nginx最详细步骤》

    出处:https://www.cnblogs.com/hltswd/p/6956264.html 第一步:在centos下面下载 nginx          wget http://nginx.or ...

  3. 改变iOS app的icon(iOS10.3)

    原文 改变iOS app的icon官方iOS10.3新增了可以让开发者去更改app的icon,接下来看看怎么更改.官方API给的东西很少,只是介绍了一个实例方法: 1 open func setAlt ...

  4. 再谈hive-1.0.0与hive-1.2.1到JDBC编程忽略细节问题

    不多说,直接上干货,这个问题一直迷惑已久,今天得到亲身醒悟. 所以,建议hadoop-2.6.0.tar.gz的用户与hive-1.0.0搭配使用.当然,也可以去用高版本去覆盖它. log4j:WAR ...

  5. 二叉树的遍历 &【NOIP2001普及组】& 洛谷 P1030 求先序排列

    题目链接 https://www.luogu.org/problemnew/show/P1030 模板题 先讲一下二叉树的遍历 二叉树的遍历 分类 性质 求法 分为三类: 先序遍历(PreOrder) ...

  6. void类型指针的基本用法

    void作为指针时可以用任意类型的的指针值都可以给它进行赋值和传递,但是输出时必须时显性输出 代码如下: #include<cstdio> #include<iostream> ...

  7. Codeforces ~ 1009B ~ Minimum Ternary String (思维)

    题意 给你一个只含有0,1,2的字符串,你可以将"01"变为"10","10"变为"01","12" ...

  8. Experimental Educational Round: VolBIT Formulas Blitz K

    Description IT City company developing computer games decided to upgrade its way to reward its emplo ...

  9. C#工具类之字典扩展类

    using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...

  10. c# mvc会话过期设置

    configuration 元素(常规设置架构)   system.web 元素(ASP.NET 设置架构)     sessionState 元素(ASP.NET 设置架构) <session ...