用roles部署nginx
2024-10-07 02:32:55
1、初始化一个role [root@bogon ~]# ansible-galaxy init /etc/ansible/roles/websrvs 查看已经创建的role
[root@bogon ~]# ls /etc/ansible/roles/
webservs 2、配置role 把初始化后 role里面没用的删除,只留下面四个目录 [root@bogon ~]# cd /etc/ansible/roles/webservs/
[root@bogon webservs]# ls
handlers README.md tasks templates vars
[root@bogon webservs]# ls templates/
index.html.j2 nginx.conf.j2 配置变量vars [root@bogon webservs]# cat vars/main.yml
---
# vars file for /etc/ansible/roles/webservs
worker_processes: 4
worker_connections: 768
max_open_files: 65506 tasks 文件内容 [root@bogon webservs]# cat tasks/main.yml
---
# tasks file for /etc/ansible/roles/webservs
- name: install nginx
command: yum install nginx -y - name: copy nginx config file
template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
notify: restart nginx - name: copy index.html
template:
src: index.html.j2
dest: /usr/share/nginx/www/index.html
mode: 0644
notify: restart nginx - name: see file
command: ls /root
notify: restart nginx handlers 文件内容: [root@bogon webservs]# cat handlers/main.yml
---
# handlers file for /etc/ansible/roles/webservs
- name: restart nginx
service: name=nginx state=restarted 模板文化内容: [root@bogon webservs]# cat templates/nginx.conf.j2
worker_processes {{ worker_processes }};
worker_rlimit_nofile {{ max_open_files }}; events {
worker_connections {{ worker_connections }};
} http {
server {
listen 80;
root /usr/share/nginx/www;
index index.html index.htm default.html index.php;
server_name loclhost;
location / {
try_files / =404;
}
} } [root@bogon webservs]# cat templates/index.html.j2
<html>
<head>
<title>welcome to american</title>
</head>
<body>
<h1>nginx, confitured by ansible</h1>
<p>if you can see this, ansible successfully installed nginx.</p> <p>{{ ansible_hostname }}</p>
</body>
</html> 3、配置playbook,把role添加进来 [root@bogon ~]# cat nginx_role.yaml
---
- hosts: webservers
become: yes
become_method: sudo
roles:
- role: webservs 4、开始执行Playbook [root@bogon ~]# ansible-playbook nginx_role.yaml
最新文章
- WaterfallFlowLayout瀑布流用重写UICollectionViewFlowLayout类实现
- html基础01
- Python 基礎 - 字符轉編碼操作
- docker--buildbot安装
- lua里面求int数组的union,diff,inter,distinct 方法实现
- [Android]Volley源码分析(二)
- HDU1176
- [编]IoT The Internet of Things (IoT) 物联网
- apecceosummit2016
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) A. Bear and Poker 分解
- 安装sinopia-ldap
- 从app里跳到appstore评论页面的实现
- Ubuntu 14.10安装SecureCRT 7.3
- 因host命令导致无法正常SHUTDOWN的实验
- 【Git之旅】2.Git对象
- 【Linux基础】Unix与Linux操作系统介绍
- UML图之类图(转)
- iOS开发 -------- 图片浏览器初步
- 【ANT】输入中文格式为乱码
- 用到的linux命令
热门文章
- Django学习系列11:在服务器中处理POST请求
- solr 基础
- IT项目开发流程
- ThinkPHP 模型方法 setInc() 和 setDec()
- JZOJ5373【NOIP2017提高A组模拟9.17】信仰是为了虚无之人
- 【SQL-分组合并字符串】把相同分组的某个字段合并为同一个字符串(使用函数)
- css中";.";,";,";,“~”和“>;”符号的意义
- 项目的Servlet类找不到
- Centos 由字符界面 init 3 切换图形界面 init 5
- &#39;vue&#39; 不是内部或外部命令,也不是可运行的程序 或批处理文件