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. 安卓程序代写 网上程序代写[原]自定义View

    一. 自定义View介绍 自定义View时, 继承View基类, 并实现其中的一些方法. (1) ~ (2) 方法与构造相关 (3) ~ (5) 方法与组件大小位置相关 (6) ~ (9) 方法与触摸 ...

  2. 从Java开发者的视角解释JavaScript

    我们无法在一篇博文里解释JavaScript的所有细节.如果你正或多或少地涉及了web应用程序开发,那么,我们的Java工具和技术范围报告揭示了,大多数(71%)Java开发者被归到了这一类,只是你对 ...

  3. Reusable async validation for WPF with Prism 5

    WPF has supported validation since the first release in .NET 3.0. That support is built into the bin ...

  4. (笔记)Linux线程编译undefined reference to 'pthread_create'

    在使用线程时,使用gcc或arm-linux-gcc编译时,会出现错误:undefined reference to 'pthread_create' 主要是以下两种原因: 1.#include &l ...

  5. Android WiFi 日志记录(ASSOC_REJECT)

    记录Android N关联拒绝之后的相关的log. 10-26 20:35:35.844 2215 2215 D wpa_supplicant: * bssid_hint=44:48:c1:d6:57 ...

  6. 杂乱所得之RPC【待整理】

    在计算机的世界里,不仅有程序内部的通信,还需要程序之间的通信,这又包含两大类:同一台主机的程序之间的通信.不同主机的程序之间的通信. 同一台主机的程序之间的通信就是IPC,IPC(Inter-proc ...

  7. (原创)关于FFmpeg的一些有关的初始化默认值的问题

    最近手头上要做一个媒体格式分析库,能解析文件,流的视频格式,编码格式等一些重要的视频参数能进行尽量多的提取.当我们做媒体相关方面的东西,自然而然就会想到FFmpeg这个强大的开源媒体库,所以我们肯定会 ...

  8. Eclipse的实用插件

    Decompiler PyDev ShellEd AnyEdit SonarLint PropertiesEditor System and Desktop Search 其它实用插件等工作中用到了再 ...

  9. android 解决输入法键盘遮盖布局问题

    /**     * @param root 最外层布局,需要调整的布局     * @param scrollToView 被键盘遮挡的scrollToView,滚动root,使scrollToVie ...

  10. php中对象(object)与数组(array)之间的相互转换

    /** * 数组 转 对象 * * @param array $arr 数组 * @return object */ function array_to_object($arr) { if (gett ...