ansible playbook 示例
http://blog.keshi.org/hogememo/2015/12/07/exploiting-ansible-jinja2
http://blog.keshi.org/hogememo/2014/10/12/ansible-credential-management
目录结构
group_vars组变量,host_vars主机变量
tvmhls/
├── channels.list.j2
├── channel.yml
├── group_vars
│ └── all.yml
├── hosts.j2
├── host_vars
│ └── 10.20.10.234.yml
├── inventory
└── readme
all.yml
---
links:
proxy.crc.01:
ip: 192.168.4.248
port: 80
proxy.ct.01:
ip: 10.10.111.31
port: 80
proxy.ct.02:
ip: 10.20.20.111
port: 80
proxy.cu.01:
ip: 10.10.111.32
port: 80
proxy.cu.02:
ip: 10.20.20.112
port: 80
10.20.10.234.yml
---
channels:
- name: BTV1HD
link: proxy.ct.01
status: disable
picture: iphone
type:
- iphone
- name: ShenZhenHD
link: proxy.cu.02
status: disable
picture: ipad
type:
- iphone
- name: CCTV3HD
link: proxy.ct.01
status: enable
picture: ipad
type:
- ipad
channel.yml
---
- hosts: '{{ hosts }}'
gather_facts: no
vars:
host_links: |
{% set l = [] %}
{% for channel in channels|sort(case_sensitive=True, attribute='link') %}
{% set _ = l.append(links[channel.link].ip+' '+channel.link) %}
{% endfor %}
{{ l | unique }}
host_channels: |
{% set c = [] %}
{% for channel in channels|sort(case_sensitive=True, attribute='name') %}
{% set s = '#' if channel.status == 'disable' else '' %}
{% for type in channel.type|sort %}
{% set p = '|1' if channel.picture == type else '' %}
{% set _ = c.append(s+channel.link+':'+links[channel.link].port|string()+'|wxcenter|'+channel.name+'|'+type+'|60'+p) %}
{% endfor %}
{% endfor %}
{{ c }}
tasks:
- name: update /etc/hosts
template: src=hosts.j2 dest=/etc/hosts owner=root group=root mode=0644
notify:
- restart svscan
- name: update /opt/script/channels.list
template: src=channels.list.j2 dest=/opt/script/channels.list owner=root group=root mode=0644
notify:
- delete channel file
- restart svscan
handlers:
- name: delete channel file
shell: /bin/find /opt/online01/{m3u8,muxer} -name "{{ item.name }}"* | /usr/bin/xargs /bin/rm -rf
when: item.status == 'disable'
with_items: "{{ channels }}"
- name: restart svscan
command: /sbin/initctl restart svscan
hosts.j2
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
{% for link in host_links -%}
{{ link }}
{% endfor %}
channels.list.j2
[/opt/download:/opt/tvmcap]
{% for channel in host_channels -%}
{{ channel }}
{% endfor %}
inventory
[wx:children]
local
backup
beijing
shanghai
[local]
127.0.0.1
[backup]
10.20.10.234
[beijing]
10.20.10.225
10.20.10.232
10.20.10.240
10.20.10.241
10.20.10.242
[shanghai]
10.20.10.230
10.20.10.233
10.20.10.237
run playbook
ansible-playbook -i inventory channel.yml --user=root --ask-pass --connection=ssh --extra-vars 'hosts=10.20.10.234'
/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.111.31 proxy.ct.01
10.20.20.112 proxy.cu.02
/opt/script/channels.list
[/opt/download:/opt/tvmcap]
#proxy.ct.01:80|wxcenter|BTV1HD|iphone|60|1
proxy.ct.01:80|wxcenter|CCTV3HD|ipad|60|1
#proxy.cu.02:80|wxcenter|ShenZhenHD|iphone|60
ansible playbook 示例的更多相关文章
- ansible笔记(11):初识ansible playbook(二)
ansible笔记():初识ansible playbook(二) 有前文作为基础,如下示例是非常容易理解的: --- - hosts: test211 remote_user: root tasks ...
- ansible笔记(10):初识ansible playbook
ansible笔记():初识ansible playbook 假设,我们想要在test70主机上安装nginx并启动,我们可以在ansible主机中执行如下3条命令 ansible test70 -m ...
- Ansible playbook 批量修改服务器密码 先普通后root用户
fsckzy Ansible playbook 批量修改服务器密码 客户的需求:修改所有服务器密码,密码规则为Rfv5%+主机名后3位 背景:服务器有CentOS6.7,SuSE9.10.11,r ...
- Ansible playbook基础组件介绍
本节内容: ansible playbook介绍 ansible playbook基础组件 playbook中使用变量 一.ansible playbook介绍 playbook是由一个或多个“pla ...
- ansible入门四(Ansible playbook基础组件介绍)
本节内容: ansible playbook介绍 ansible playbook基础组件 playbook中使用变量 一.ansible playbook介绍 playbook是由一个或多个“pla ...
- ansible playbook模式及语法
一.什么是playbook及其组成 什么是playbook playbook 翻译过来就是"剧本" playbook的组成 play:定义的是主机的角色 task:定义的是具体执行 ...
- ansible - playbook(剧组)
目录 ansible - playbook(剧组) 常用命令 五种传参方式 常用元素详解 tags handlers template when 循环 嵌套循环 ansible - playbook( ...
- Ansible--02 ansible playbook的应用
目录 Ansible playbook的应用 什么是playbook playbook的组成 playbook和Ad-Hoc对比 YAML语法 安装httpd练习 rsyncd实战 实战1: 实战2: ...
- ansible playbook详解
ansible playbook是由yml语法书写,结构清晰,可读性强,所以必须掌握yml基础语法 语法 描述 缩进 YAML使用固定的缩进风格表示层级结构,每个缩进由两个空格组成,不能使用tabs键 ...
随机推荐
- js的一点
1.js中实现继承的方法 1.js原型(prototype)实现继承 <SPAN style="<SPAN style="FONT-SIZE: 18px"&g ...
- 学习笔记-Java编程思想
2016-01-03 Swith(整数选择因子):必须是int或char这样的整数值. Java中不包含goto语句,但是可以通过标识符实现类似的控制.
- C#导出Excel,并设置简单格式
protected void ExportExcel(DataTable dt) { string fileName = “FileName”; Microsoft.Office.Interop.Ex ...
- android NDK debug 遇到的问题与解决方法
最近在研究android NDK 的eclipse调试,遇到点问题,总结一下: 1.Unknown Application ABI :在application.mk里面添加APP_PLATFORM ...
- 使用OpenLDAP构建基础账号系统
LDAP - Lightweight Directory Access Protocol,对该协议的具体应用,常见的是微软的Active Directory服务和Linux上的OpenLDAP组件. ...
- css 多个不定数量提交按钮居中显示,纯css解决
前几天在公司修改一个css 多个按钮居中问题,其实这样的问题很多前端程序员都遇到过,举个例子吧: 在一行中有三个按钮或是两个按钮...个数不定,然后间距固定:然后就有很多人把所有按钮放到一个div中, ...
- 查看Visual Studio异常内容
If Entity Framework throws a validation exception when saving, Visual Studio reports the message, Va ...
- Nginx去除版本号
1.在配置文件中的 http节点中加入server_tokens off; 2.更改源码隐藏nginx软件的名称 1). 查看Nginx编译的参数/usr/local/nginx/sbin/nginx ...
- OAF_开发系列28_实现OAF中反编译获取class包代码JD Compiler(案例)
20150730 Created By BaoXinjian
- Spring Integration
@ContextConfiguration directs Spring's test runner to locate a configuration file with the same name ...