3.yum安装集中式LNMP--剧本

文章目录

  • yum安装集中式LNMP--剧本
    • 创建剧本

yum安装集中式LNMP–剧本

创建剧本

vim /etc/ansible/hosts

[lnmpservers]
192.168.242.70
- name: nginx play
  hosts: lnmpservers
  remote_user: root
  vars:
  - http_port: 192.168.242.70:80
  - http_hostname: www.ggl.com
  - root_dir: /usr/share/nginx/html
  - http_remote: 192.168.242.70:9000
  - service: nginx

  tasks:
  - name: disable firewalld
    service: name=firewalld  state=stopped  enabled=no
    
  - name: disable selinux
    shell: "/usr/sbin/setenforce 0"
    ignore_errors: true
  
  - name: copy nginx.repo
    copy: src=nginx.repo dest=/etc/yum.repos.d/

  - name: install nginx
    yum: name={{service}} state=latest

  - name: copy index.php
    copy: src=index.php dest={{root_dir}}

  - name: copy nginx.conf
    template: src=default.conf.j2 dest=/etc/nginx/conf.d/default.conf
    notify: reload nginx

  - name: start nginx
    service: name={{service}} state=started enabled=yes
  handlers:
  - name: reload nginx
    service: name={{service}} state=reloaded
    
- name: mysql play
  hosts: lnmpservers
  remote_user: root
  tasks:
  - name: yum remove mariadb
    yum: name=mariadb* state=absent

  - name: install rpm
    shell: wget -P /etc/yum.repos.d/ http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
    ignore_errors: true

  - name: install noarch.rpm
    shell: yum -y install /etc/yum.repos.d/mysql57-community-release-el7-10.noarch.rpm
    ignore_errors: true

  - name: replace wprd
    replace: path=/etc/yum.repos.d/mysql-community.repo regexp='gpgcheck=1' replace='gpgcheck=0'
    ignore_errors: true

  - name: install mysql
    yum: name="mysql-server"

  - name: start mysqld
    service: name=mysqld state=started enabled=yes


  - name: login mysql
    shell: mysql -uroot -p"$(grep "password" /var/log/mysqld.log | awk 'NR==1 {print $NF}')" --connect-expired-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin@123';"
    ignore_errors: true

  - name: grantmysql
    shell: mysql -uroot -pAdmin@123 -e "grant all privileges on *.* to root@'%' identified by 'Admin@123' with grant option;"
    ignore_errors: true


- name: php play
  hosts: lnmpservers
  remote_user: root
  tasks:
  vars: 
  - timezone: Asia/Shanghai
  - user_name: php
  - http_port: 192.168.242.70:9000
  - remote_addr: 192.168.242.70
  - mysql_dir: /var/lib/mysql/mysql.sock
  tasks:    
  - name: install yum repo
    shell: "rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm && rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm"
    ignore_errors: true

  - name: install php
    with_items:
    - php72w
    - php72w-cli
    - php72w-common
    - php72w-devel
    - php72w-embedded
    - php72w-gd
    - php72w-mbstring
    - php72w-pdo
    - php72w-xml
    - php72w-fpm
    - php72w-mysqlnd
    - php72w-opcache
    yum: name={{item}}

  - name: create php user
    user: name={{user_name}}


  - name: modify php.ini
    template: src=php.ini.j2 dest=/etc/php.ini
    notify: reload php

  - name: copy www.conf
    copy: src=www.conf dest=/etc/php-fpm.d/www.conf

  - name: start php
    service: name=php-fpm state=started enabled=yes
  handlers:
  - name: reload php
    service: name=php-fpm state=reloaded
##在剧本的当前目录中,需要准备需要的文件

index.php
nginx.repo
default.conf.j2

www.conf
php.ini.j2

你可能感兴趣的:(12.Ansible,android,adb)