Ansible之YMAL语法介绍以及playbook详解
来源:互联网 发布:朝鲜中国知乎 编辑:程序博客网 时间:2024/06/04 18:32
转自:http://houzhimeng.blog.51cto.com/3938990/1734009
1
2
3
4
5
6
7
name: John Smith
age: 41
gender: Male
spouse:
name: Jane Smith
age: 37
gender: Female
1
2
3
4
5
6
- name: Jimmy Smith
age: 17
gender: Male
- name: Jenny Smith
age 13
gender: Female
1
2
3
4
- hosts: webservers
roles:
- common
- { role: foo_app_instance,
dir
:
'/web/htdocs/a.com'
, port: 8080
1
2
3
4
- hosts: webservers
roles:
- common
- { role: foo_app_instance,
dir
:
'/web/htdocs/a.com'
, port: 8080
1
ntp.magedu.com
1
2
3
[webservers]
www1.magedu.com:2222
www2.magedu.com
1
2
3
4
[dbservers]
db1.magedu.com
db2.magedu.com
db3.magedu.com
1
2
3
4
[webservers]
www[01:50].example.com
[databases]
db-[a:f].example.com
1
2
3
4
5
6
7
8
9
10
11
12
- hosts: webservs
remote_user: root
tasks:
- name: create nginx group
group: name=nginx system=
yes
gid=208
- name: create nginx user
user: name=nginx uid=208 group=nginx system=
yes
- hosts: dbservs
remote_user: root
tasks:
- name: copy
file
to dbservs
copy: src=
/etc/inittab
dest=
/tmp/inittab
.ansible
1
2
3
4
5
6
7
8
9
- hosts: webservs
remote_user: root
tasks:
- name:
install
httpd package
yum: name=httpd state=latest
- name:
install
configuration
file
for
httpd
copy: src=
/tmp/httpd
.conf dest=
/etc/httpd/conf/httpd
.conf
- name: start httpd service
service: enabled=
true
name=httpd state=started
1
2
3
4
5
handlers:
- name: restart memcached
service: name=memcached state=restarted
- name: restart apache
service: name=apache state=restarted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
- hosts: webservs
remote_user: root
tasks:
- name:
install
httpd package
yum: name=httpd state=latest
- name:
install
configuration
file
for
httpd
copy: src=
/tmp/httpd
.conf dest=
/etc/httpd/conf/httpd
.conf
notify:
- restart httpd
- name: start httpd service
service: enabled=
true
name=httpd state=started
handlers:
- name: restart httpd
service: name=httpd state=restarted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- hosts: webservs
remote_user: root
vars:
- package: httpd
- service: httpd
tasks:
- name:
install
httpd package
yum: name={{ package }} state=latest
- name:
install
configuration
file
for
httpd
copy: src=
/tmp/httpd
.conf dest=
/etc/httpd/conf/httpd
.conf
notify:
- restart httpd
- name: start httpd service
service: enabled=
true
name={{ service }} state=started
handlers:
- name: restart httpd
service: name=httpd state=restarted
1
2
3
4
5
6
7
8
- hosts: all
remote_user: root
vars:
- username: user10
tasks:
- name: create {{ username }} user
user: name={{ username }}
when: ansible_fqdn ==
"node2.magedu.com"
1
2
3
4
tasks:
- name:
"shutdown Debian flavored systems"
command
:
/sbin/shutdown
-h now
when: ansible_os_family ==
"Debian"
1
2
3
4
5
6
7
8
9
10
tasks:
-
command
:
/bin/false
register: result
ignore_errors: True
-
command
:
/bin/something
when: result|failed
-
command
:
/bin/something_else
when: result|success
-
command
:
/bin/still/something_else
when: result|skipped
1
2
3
4
5
- name: add several
users
user: name={{ item }} state=present
groups
=wheel
with_items:
- testuser1
- testuser2
1
2
3
4
- name: add user testuser1
user: name=testuser1 state=present
groups
=wheel
- name: add user testuser2
user: name=testuser2 state=present
groups
=wheel
1
2
3
- {name: apache, conf: conffiles
/httpd
.conf}
- {name: php, conf: conffiles
/php
.ini}
- {name: mysql-server, conf: conffiles
/my
.cnf}
1
2
3
4
- name:
install
configuration
file
for
httpd
template: src=
/root/templates/httpd
.conf.j2 dest=
/etc/httpd/conf/httpd
.conf
tags:
- conf
1
2
3
4
5
- hosts: webservers
roles:
- common
- { role: foo_app_instance,
dir
:
'/opt/a'
, port: 5000 }
- { role: foo_app_instance,
dir
:
'/opt/b'
, port: 5001 }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@hzm ~]
# tree ansible_playbooks/
ansible_playbooks/
└── roles
├── dvsrvs
│ ├── files
#存放由copy或script等模块调用的文件;
│ ├── handlers
#此目录中应当包含一个main.yml文件,用于定义此角色用到的各handler;在handler中使用include包含的其它的handler文件也应该位于此目录中;
│ ├── meta
#应当包含一个main.yml文件,用于定义此角色的特殊设定及其依赖关系;ansible 1.3及其以后的版本才支持;
│ ├── tasks
#至少应该包含一个名为main.yml的文件,其定义了此角色的任务列表;此文件可以使用include包含其它的位于此目录中的task文件;
│ ├── templates
#template模块会自动在此目录中寻找Jinja2模板文件;
│ └── vars
#应当包含一个main.yml文件,用于定义此角色用到的变量
└── websrvs
├── files
├── handlers
├── meta
├── tasks
├── templates
└── vars
阅读全文
0 0
- Ansible之YMAL语法介绍以及playbook详解
- Ansible Playbook 介绍
- ansible之playbook入门
- Ansible之playbook学习一
- ansible之创建可复用playbook
- Ansible playbook
- ansible-playbook
- ansible playbook
- ansible playbook
- Ansible学习之playbook(4)
- ansible-playbook实战之批量安装mysql
- ansible-playbook实战之批量安装lamp
- 第一百一十天 : ansible-playbook 使用详解
- ansible之yaml语法
- ansible playbook最佳实践
- ansible-playbook简介
- Ansible playbook简单示例
- Ansible 基础入门-Playbook
- OC和Swift纯代码进行Autolayout布局
- query.setFirstResult解析
- Java单例模式
- Oracle重做日志文件组-新增、删除
- 解决Call to unavailable function 'system': not available on iOS
- Ansible之YMAL语法介绍以及playbook详解
- 页面的两种打印方式
- 深入理解Java虚拟机读书笔记--第二章 Java 内存区域与内存溢出异常
- jquery.cookie.js
- pads 转 allegro
- 迭代阀值
- 查找 atom 编辑文件所在的文件位置
- Python爬虫入门-python之爬取pexels高清图片
- Context细节