• ansible批量部署Nginx


    一、目录环境

    [root@wd-code deploy_nginx]# tree
    .
    ├── hosts
    ├── roles
    │   ├── common
    │   │   └── tasks
    │   │       └── main.yml
    │   └── nginx
    │       ├── files
    │       │   └── nginx-1.14.0.tar.gz
    │       ├── tasks
    │       │   └── main.yml
    │       ├── templates
    │       └── vars
    │           └── main.yml
    └── site.yml
    
    8 directories, 6 files

    二、common目录为公共目录

    main.yml文件

    ---
    - name: Install deps
      yum: name={{ item }} state=present
      #become: true
      #become_user: root
      #become_method: su
      with_items:
        - gcc
        - make
        - zlib-devel
        - openssl-devel
        - pcre-devel
        - pcre
        - zlib
        - openssl

    三、nginx目录下

    tasks目录下main.yml文件

    ---
    - name: Copy Nginx
      copy: src=nginx-1.14.0.tar.gz dest=/tmp
    
    - name: tar nginx
      unarchive:
        src: /tmp/nginx-1.14.0.tar.gz
        dest: "{{ install_bashdir }}"
        copy: no
    
    - name: Install Nginx
      shell: "cd {{ install_bashdir }}/nginx-1.14.0 && ./configure --prefix={{ install_bashdir }}/nginx --user={{ nginx_user }} --group={{ nginx_group }} --with-http_stub_status_module --with-http_ssl_module && make && make install"
    
    - name: chown work Permission
      file: dest={{ install_bashdir }}/nginx owner={{ nginx_user }} group={{ nginx_user }} recurse=yes
    - name: remove nginx package
      file: dest={{ install_bashdir }}/nginx-1.14.0 state=absent
    #- name: start nginx
    #  shell: cd "{{ install_bashdir }}" && nginx/sbin/nginx 

    四、vars变量目录

    main.yml文件

    install_bashdir: /home/work
    nginx_user: root 
    nginx_group: root

    五、入口文件site.yml

    site.yml

    ---
    - hosts: nginx
      gather_facts: no
      remote_user: root 
      
      roles:
        - role: common
        - role: nginx
  • 相关阅读:
    ASP生成静态文件编码为UTF-8格式的HTML文件
    asp图片化电话号码,避免蜘蛛之类爬走用户隐私
    动态上传多个文件(asp)
    简单测试IIS下的UrlRewrite技术
    mac配置tomcat
    CSS盒子
    CSS
    HTML
    从java到python
    HTTP协议
  • 原文地址:https://www.cnblogs.com/zhangzihong/p/10470302.html
Copyright © 2020-2023  润新知