zoukankan      html  css  js  c++  java
  • 10.ansible 利用playbook部署LAMP环境

    基本文件目录如下:
    httpd所需软件:httpd mariadb mariadb-server php  php-mysql   gd    php-gd
    [root@ansible role]# ls
    httpd          site_nginx.retry  site.retry
    mariadb  php-apache  site_apache.yaml 

    [root@ansible role]# cat site_apache.yaml
    ---
    - hosts: group
      roles:
      - httpd
      - php-apache
      - mariadb

    1.httpd目录
    [root@ansible role]# cd httpd/
    [root@ansible httpd]# ls
    files  handlers  tasks  templates  vars

    [root@ansible httpd]# cat files/index.html
    hello world
    [root@ansible httpd]# cat handlers/main.yaml
    ---
    - name: reload httpd.service
      service: name=httpd state=reloaded
    [root@ansible httpd]# cat tasks/main.yaml
    ---
    - name: install httpd
      yum: name=httpd state=present

    - name: copy httpd configure file
      template: src=httpd.conf.j2 dest=/etc/httpd/conf/httpd.conf
      notify: reload httpd.service

    - name: copy index.html
      copy: src=index.html dest=/var/www/html/index.html

    - name: start and enable httpd
      service: name=httpd state=started enabled=yes

    [root@ansible httpd]# ls templates/
    httpd.conf.j2

    在httpd.conf.j2中定义变量

    Listen {{ httpd_port }}

    [root@ansible httpd]# cat vars/main.yaml
     httpd_port: 80

    2.mariadb目录
    [root@ansible role]# cd mariadb/
    [root@ansible mariadb]# ls
    handlers  tasks  templates  vars        //mariadb 不需要测试首页可以不写

    [root@ansible mariadb]# cat handlers/main.yaml
    ---
    - name: restart mariadb.service
      service: name=mariadb state=restarted

    [root@ansible mariadb]# cat handlers/main.yaml
    ---
    - name: restart mariadb.service
      service: name=mariadb state=restarted
    [root@ansible mariadb]# cat tasks/main.yaml
    ---
    - name: install mariadb
      yum: name={{ item }} state=present
      with_items:
      - mariadb
      - mariadb-server

    - name: copy mariadb configure file
      template: src=my.cnf.j2 dest=/etc/
      notify: restart mariadb.service

    - name: start and enable mariadb
      service: name=mariadb state=started enabled=yes

    [root@ansible mariadb]# ls templates/
    my.cnf.j2

    [root@ansible mariadb]# cat vars/main.yaml
     datadir: /var/lib/mysql
     socket: /var/lib/mysql/mysql.sock

    3.apache中php目录
    [root@ansible php-apache]# ls
    files  handlers  tasks  templates

    [root@ansible php-apache]# cat handlers/main.yaml
    ---
    - name: restart httpd
      service: name=httpd state=restarted

    [root@ansible php-apache]# cat handlers/main.yaml
    ---
    - name: restart httpd
      service: name=httpd state=restarted
    [root@ansible php-apache]# cat tasks/main.yaml
    ---
    - name: install php-fpm
      yum: name={{ item }} state=present
      with_items:
      - php
      - php-gd
      - php-mysql
      - gd

    - name: copy php configure file
      template: src=php.ini.j2 dest=/etc/php.ini
      notify: restart httpd

    - name: copy index.php
      copy: src=index.php dest=/var/www/html/index.php
      notify: restart httpd

    [root@ansible php-apache]# ls templates/
    php.ini.j2                                          //不定义变量可以不创建vars目录

  • 相关阅读:
    原生JS实现new方法、new一个对象发生的四部、new里面常用的优先级
    svg image标签降级技术
    ReflectionToStringBuilder使用
    记一次未解决的异常:java.lang.NoClassDefFoundError: net/sf/json/JSONObject
    eclipse安装Run-Jetty-Run插件,修改实时生效
    jdbcTemplate:包含占位符的SQL无法打印参数信息
    jdbcTemplate异常:like模糊查询报错(Parameter index out of range (1 > number of parameters)
    Spring整合MyBatis
    springmvc整合slf4j、log4j记录文本日志
    Java环境配置
  • 原文地址:https://www.cnblogs.com/hackerlin/p/12553243.html
Copyright © 2011-2022 走看看