美文网首页
ansible搭建可道云

ansible搭建可道云

作者: UncleZ_strive | 来源:发表于2019-10-10 21:38 被阅读0次

编写 ansible playbook

[root@manager project1]# cat kodcloud_server.yml
- hosts: web
  tasks:
    - name: Installed Nginx repo
      yum_repository:
        name: nginx
        description: nginx repos
        baseurl: http://nginx.org/packages/centos/$releasever/$basearch/
        gpgcheck: no

    - name: Installed PHP repo
      yum_repository:
        name: webtatic-php
        description: php repos
        baseurl: http://us-east.repo.webtatic.com/yum/el7/x86_64/
        gpgcheck: no

    - name: Installed Nginx and PHP
      yum:
        name: "{{ packages }}"
      vars:
        packages:
          - nginx
          - php71w
          - php71w-cli
          - php71w-common
          - php71w-devel
          - php71w-gd
          - mod_php71w
          - php71w-fpm
          - php71w-opcache

    - name: Create Group
      group:
        name: www
        gid: 666

    - name: Create User
      user:
        name: www
        group: www
        uid: 666
        create_home: no
        shell: /sbin/nologin

    - name: Configure nginx.conf
      copy:
        src: ./file/nginx.conf.j2
        dest: /etc/nginx/nginx.conf
      notify: Restart Nginx Server

    - name: Configure php.conf
      copy:
        src: ./file/www.conf.j2
        dest: /etc/php-fpm.d/www.conf
      notify: Systemd PHP-FPM Server

    - name: Add Nginx VirHost 
      copy:
        src: ./file/kodcloude.com.conf.j2
        dest: /etc/nginx/conf.d/kodcloude.com.conf
      notify: Restart Nginx Server

    - name: Init Nginx BseEnv
      file:
        path: /code
        state: directory
        owner: www
        group: www
        recurse: yes

    - name: Push KodCloud Code
      synchronize:
        src: ./file/kod
        dest: /code/

    - name: Chomod kodcloud
      file:
        path: /code
        owner: www
        group: www
        mode: 0777
        recurse: yes

    - name: Systemd Nginx Server
      systemd:
        name: nginx
        state: started
        enabled: yes

    - name: Systemd PHP-FPM Server
      systemd:
        name: php-fpm
        state: started
        enabled: yes
  handlers:
    - name: Restart Nginx Server
      systemd:
        name: php-fpm
        state: restarted 

准备Nginx虚拟主机

[root@manager project1]# cat file/kodcloude.com.conf.j2 
server {
        listen 80;
        server_name kodcloud.com;
        root /code/kod;
        client_max_body_size 500m;

        location / {
                index index.php index.html;
        }

        location ~ \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

准备file/www.conf.j2, file/nginx.conf.j2

相关文章

网友评论

      本文标题:ansible搭建可道云

      本文链接:https://www.haomeiwen.com/subject/rdtzpctx.html