Ansible 配置文件 :

[root@center /data/ansiblework]# cat ansible.cfg
[defaults]
remote_user = root
remote_port = 22
inventory = /data/ansiblework/hosts
log_path = /var/log/ansible.log
host_key_checking = False
retry_files_enabled = False

Ansible 主机配置 :

[root@center /data/ansiblework]# cat hosts
[new_hosts]
192.168.1.1
192.168.1.2
192.168.1.3 [new_hosts:vars]
ansible_ssh_port = 22 # 远程连接端口
ansible_ssh_user = root # 远程连接用户
ansible_ssh_pass = 123456 # 远程连接密码

Ansible Playbook :

[root@center /data/ansiblework]# cat onekey_init.yml
---
- hosts: new_hosts
gather_facts: True
tasks:
- name: 下发公钥到新主机
authorized_key: user=root key="{{ lookup('file', '/root/.ssh/id_rsa.pub') }}" - name: 检查系统版本
fail: msg="系统版本错误,请检查"
when: ansible_facts['distribution'] != "CentOS" or ansible_facts['distribution_major_version'] != "" - name: 检查是否挂载/data目录
fail: msg="/data目录未挂载,请检查"
when: not ansible_mounts[1].mount == "/data" - name: 检查/data目录是否挂载异常
fail: msg="/data目录小于250G,请检查"
when: ansible_mounts[1].size_total | int < 250000000000 - name: 拷贝初始化脚本
template: src={{ item }} dest=/tmp/{{ item }} owner=root group=root
with_items:
- base_lnmp.sh
- lnmp_install.sh - name: 检查是否安装过LNMP
shell: if [ -f /tmp/install.log ];then grep 'Install Complete' /tmp/install.log;fi || echo None
register: result - name: 开始安装LNMP
shell: /bin/sh /tmp/lnmp_install.sh > /tmp/install.log
when: "'Install Complete' not in result.stdout" - name: 检查是否安装按成
shell: if [ -f /tmp/install.log ];then grep 'Install Complete' /tmp/install.log;fi || echo None
register: result
- fail: msg="安装失败,请登录到安装机器查看/tmp/install.log查看原因"
when: "'Install Complete' not in result.stdout" - name: 检查LNMP安装状态
shell: ps aux | egrep "(php|nginx|mysql|zabbix|salt)"
register: result
- fail: msg="{{ item }}安装异常,请检查"
when: "item not in result.stdout"
with_items:
- php
- mysql
- nginx
- zabbix
- salt-minion

Ansible 实战:一键安装 LNMP的更多相关文章

  1. Centos6.5中 一键安装LNMP 安装Yii2.0 手工配置

    1.一键安装LNMP cd /usr wget -c http://soft.vpser.net/lnmp/lnmp1.2-full.tar.gz tar zxf lnmp1.-full.tar.gz ...

  2. Shell脚本一键安装LNMP环境

    https://sourceforge.net/projects/opensourcefile/files/ Nginx是一款高性能的HTTP和反向代理服务器.Nginx在反向代理,Rewrite规则 ...

  3. 一键安装LNMP(适合centos7)

    1.准备工作,下载源码包 wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar ...

  4. Linux一键安装LNMP环境

    Linux一键安装LNMP环境 官方地址:https://lnmp.org/. 参考安装步骤:https://lnmp.org/install.html. 一键安装可以选择mysql版本.php版本, ...

  5. Linux安装swoole拓展 (一键安装lnmp后安装可用完美)

    一键安装lnmp后安装可用完美 swoole(一键安装完lnmp重启下,之前出现502一直解决不了,不清楚啥情况) 找到对应php版本,在lnmp文件夹的src 1.安装swoole cd /usr/ ...

  6. 一键安装Lnmp教程

    LNMP一键安装包 系统需求: CentOS/RHEL/Fedora/Debian/Ubuntu/Raspbian Linux系统 需要3GB以上硬盘剩余空间 128M以上内存,Xen的需要有SWAP ...

  7. 【Linux】Centos6.8下一键安装Lnmp/Lamp环境

    [下载一键安装软件包] 百度云地址:https://pan.baidu.com/s/1TZqGKtE-46gxW96Ptfp4gA 网址:https://lnmp.org/ [步骤] 通过第三方远程工 ...

  8. 一键安装LNMP/LAMP

    安装步骤:1.使用putty或类似的SSH工具登陆VPS或服务器: 登陆后运行:yum install screen安装  screen screen -S lnmp创建一个名字为lnmp的会话 2. ...

  9. 一键安装 lnmp/lamp/lanmp

    1.使用putty或类似的SSH工具登陆VPS或服务器 # screen -S lnmp 如果提示screen: command not found 命令不存在可以执行:yum install scr ...

随机推荐

  1. Qt之创建自定义类型

    摘要: 简述 当使用Qt创建用户界面时,特别是那些带有特殊控制和特征的界面时,开发者通常需要创建新数据类型来扩展或替换Qt现有的的值类型集合. 标准类型,比如:QSize.QColor和QString ...

  2. 自然语言交流系统 phxnet团队 创新实训 个人博客 (五)

    有关我们这个项目:智能自然语言交流系统,所借鉴的技术有: 第一:我们使用了科大讯飞的在线语音转换,涉及的有文本传给云端服务器的文字转换成语音和本地的语音上传给服务器转换成文字. 涉及的相关的代码有: ...

  3. Policy Gradient

    Policy Gradient是区别于Q-Learning为代表的value based的方法.policy gradient又可以叫reinforce算法(Williams, 1992). 如今的A ...

  4. TPshop隐藏index.php

    有些朋友提到关于TPshop 隐藏index.php 一问题, 可以修改 Application\Common\Conf\config.php 文件代码 'common', 'AUTH_CODE' = ...

  5. 获取Java正在执行的方法

    new Object(){}.getClass().getEnclosingMethod().getName(); Thread.currentThread().getStackTrace()

  6. PyQt的signal 和 solit的补充

    from PyQt5.QtWidgets import (QWidget , QVBoxLayout , QHBoxLayout, QLineEdit, QPushButton) from PyQt5 ...

  7. 使用w查看系统负载 vmstat命令 top命令 sar命令 nload命令

    w/uptime 查看系统负载 w查看系统负载,uptime跟w一样. [root@centos7 ~]# w 22:34:10 up 6 days, 23:10,  4 users,  load a ...

  8. SharePoint 使用ECMAscript对象模型来操作Goup与User

    这里总结了关于使用ECMAscript对象模型来操作Goup与User的常用情况,内容如下:     1.取得当前Sharepoint网站所有的Groups     2.获取当前登录用户的Title与 ...

  9. [转]jmeter 自定义测试脚本

    http://blog.csdn.net/kash_chen007/article/details/37690411 http://wangym.iteye.com/blog/731729 1.创建一 ...

  10. iview给radio按钮组件加点击事件

    <RadioGroup v-model="formValidate.phone"> <Radio label="phone">商家电话& ...