ansible案例-安装nginx
一、创建目录:
mkidr -p playbook/{files,templates}
二、自定义index.html文件
$ vim playbook/templates/index.html.j2
---------------------------------------------------------->
<html>
<head>
<title>Welcome to ansible</title>
<body>
<h1>nginx,configured by Ansible</h1>
<p>If you cat see this,Ansible successfully installed nginx.</p>
</body>
</head>
</html>
三、配置web_nginx.yml
$ vim playbook/web_nginx.yml
--------------------------------------------->
- hosts: 172.16.1.201 //目标主机
remote_user: root //远程主机用户
tasks:
- name: install epel-release //centos安装nginx前,需先安装epel-release
command: yum install epel-release -y
- name: install libselinux-python //利用ansible copy 文件需安装此包
command: yum install libselinux-python -y
- name: install nginx
command: yum install nginx -y
- name: copy html
copy: src="templates/index.html.j2" dest="/usr/share/nginx/html/index.html" //copy自定义html到指定目录
tags: html
notify:
- server restart
- name: server start
service: name=nginx state=started enabled=true //启动并设置开机启动服务
handlers:
- name: server restart
service: name=nginx state=restarted
四、执行配置文件web_nginx.yml
$ ansible-playbook web_nginx.yml
结果如下图

运行http://172.16.1.201查看结果

ansible案例-安装nginx的更多相关文章
- ansible的playbook进行yum批量安装nginx最新版本
环境:centos7 版本:nginx最新版本 软件: ansible 作用: 进行批量执行不同机器上,进行安装nginx版本 检查脚本是否正确: [root@ansible-test ansible ...
- Ansible 使用 Playbook 安装 Nginx
思路:先在一台机器上编译安装好 Nginx,打包,然后通过 Ansible 下发 [root@localhost ~]$ cd /etc/ansible/ [root@localhost ansibl ...
- ansible安装nginx
ansible安装nginx(实现回滚发布功能:下一篇博客.没想到写长了) 一.准备工作 1.准备两台机器 sai: 192.168.131.132 ——> ansible的服务端 luojy ...
- 【ansible】使用ansible安装nginx
一.主机准备 ServerIP:10.10.10.102 ClientIP: 10.10.10.103,10.10.10.104 二.安装ansible yum -y install ansible ...
- 使用Ansible安装部署nginx+php+mysql之安装nginx(1)
使用Ansible安装nginx 1.nginx.yaml文件 --- - hosts: clong remote_user: root gather_facts: no tasks: # 安装epe ...
- ansible roles实践——安装nginx
1.创建roles 在/etc/ansible/roles目录下 1.1 手动创建需要的目录 1.2 使用命令创建,用不到的目录可以创建为空目录,但不可以不创建. 创建目录[root@master] ...
- linux系统虚拟机下安装nginx基础
虽然安装nginx什么的 .以及如何配置等等一系列的资料案例已经很多了 但是作为菜鸟的我还是搞了半天哈 官网上面也有.但是一些细节方面的并没有说明.导致踩了半天坑才搞好 本案例的系统环境 wi ...
- 安装nginx和nginx-gridfs和mongodb
1.安装依赖包: [root@mongo_rs1 ~]# yum -y install pcre-devel openssl-devel zlib-devel git gcc gcc-c++ [roo ...
- [k8s]kubespray(ansible)自动化安装k8s集群
kubespray(ansible)自动化安装k8s集群 https://github.com/kubernetes-incubator/kubespray https://kubernetes.io ...
随机推荐
- struts2核心和工作原理
转至:http://blog.csdn.net/laner0515/article/details/27692673 在学习struts2之前,首先我们要明白使用struts2的目的是什么?它能给我们 ...
- PHP保存数组到文件中的方法
ThinkPHP自3.1以后的版本,F函数保存数组时先序列化后再保存到文件中,因为我需要使用C方法来读取自定义配置文件,故需要把PHP数组保存到文件中以便C方法读取,PHP保存数组到文件的方法如下: ...
- POJ 1611并查集
我发现以后写题要更细心,专心! #include<iostream>#include<algorithm>#include<stdio.h>#include< ...
- Hibernate学习---第十二节:Hibernate之锁机制&乐观锁实现
1.悲观锁 它指的是对数据被外界修改保持保守态度,因些,在整个数据处理过程中,将数据牌锁定状态.悲观锁的实现,往往依靠数据库提供的锁机制(也只有数据库层的锁机制才能保证数据访问的排他性,否则,即使在本 ...
- python MLP 神经网络使用 MinMaxScaler 没有 StandardScaler效果好
MLP 64,2 preprocessing.MinMaxScaler().fit(X) test confusion_matrix:[[ ...
- LSM Tree 学习笔记——本质是将随机的写放在内存里形成有序的小memtable,然后定期合并成大的table flush到磁盘
The Sorted String Table (SSTable) is one of the most popular outputs for storing, processing, and ex ...
- vuex使用mapActions报错解决办法
先贴上报错: vuex2增加了mapGetters和mapActions的方法,借助stage2的Object Rest Operator 所在通过 methods:{ ...mapActions([ ...
- 将double型小数点后面多余的零去掉
/** 函数功能:将数值小数点后面多余的零清空.* 参数描述:* [in] aSource - 输入的源数值:* [out] aDestination - 输出截取后的数值* ...
- python习题-用交集方式产生随机密码
# 1.写一个产生密码的程序,# 输入次数,输入多少次就产生多少条数据,# 要求密码必须包含大写字母.小写字母和数字,长度8位,不能重复 import string ,random num=input ...
- 6 Python 数据类型—字符串
字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串. 创建字符串很简单,只要为变量分配一个值即可. var1 = 'Hello World!' var2 = ...