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键 ...
随机推荐
- Atom编辑器添加eclipse快捷键
Settings - Keybindings - 点击"your keymap file" 'atom-text-editor': 'alt-/': 'autocomplete- ...
- Google Dapper-大规模分布式系统的基础跟踪设施
[说明:本文是阅读Google论文"Dapper, a Large-Scale Distributed Systems Tracing Infrastructure"之后的一个简要 ...
- 服务器Ubuntu16.04下连接锐捷
最近搞深度学习,老师买了一台服务器.双系统,win7和Ubuntu16.04,但是联网是遇到了问题. 输入ifconfig时,发现根本就找不到eth0和eth1,只有evp0s25和evp0s90,o ...
- http请求相关
1.POST方式向服务器发送AJAX请求时 设置请求头 application/x-www-form-urlencoded 2.表单上传文件时 设置请求头 multipart/form-d ...
- Ubuntu 16.04中安装Chromium浏览器
引用:http://www.linuxidc.com/Linux/2016-05/131097.htm 通过ppa,安装最新版本的Chromium浏览器 sudo add-apt-repository ...
- WIN SERVER 2008 R2 VPN
http://blog.csdn.net/popelovevivi/article/details/9408851 -- 还差最重要一步. 在“本地用户和组”-“用户”-右键一个你想VPN登录的用户名 ...
- 常用SQL Server日期格式化
Select CONVERT(varchar(100), GETDATE(), 8): 10:57:46 Select CONVERT(varchar(100), GETDATE(), 24): 10 ...
- 重写类的Equals以及重写Linq下的Distinct方法
当自定义一个类的时候,如果需要用到对比的功能,可以自己重写Equals方法,最整洁的方法是重写GetHashCode()方法. 但是,这个方法只适用于对象自身的对比(如if(a==b))以及字典下的C ...
- Python socket超时
#server.py import socket s=socket.socket() s.bind(('127.0.0.1',2000)) s.listen(5) while 1: cs,addres ...
- ./upload/source/class/class_core.php
定义了core这个类 error_reporting(E_ALL); error_reporting() 设置 PHP 的报错级别并返回当前级别.可以参考手册. define('IN_DISCUZ', ...