使用ansible-playbook编译安装nginx

继续学习ansible-playbook的使用,熟悉使用更多jinja2模板语法,下面是我的脚本,后面会继续完善,使用更多的模板语法

nginx.yml文件

---
- hosts: node
  remote_user: root
  vars: 
    target_dir: '/usr/local/src/'
    nginx_version: '1.17.4'
  tasks:
    - name: 安装依赖包
      shell: yum install -y make apr* autoconf automake curl-devel gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel cmake

    - name: 复制nginx文件
      copy: src=nginx-{{ nginx_version }}.tar.gz dest={{ target_dir }}

    - name: 复制一键安装脚本
      copy: src=nginx_install.sh dest={{ target_dir }} mode=0755

    - name: 执行一件安装脚本
      shell: /bin/bash {{ target_dir }}nginx_install.sh {{ nginx_version }}

nginx安装脚本

#!/bin/bash
nginx_dir='/usr/local/nginx'
if [ ! -e ${nginx_dir} ]
then
    mkdir -p ${nginx_dir}
fi
cd /usr/local/src
if [ ! -z $1 ]
then
    tar -zxvf nginx-$1.tar.gz
else
    exit 1
fi
cd nginx-$1
groupadd  www
useradd -g  www www -s /sbin/nologin
./configure --prefix=${nginx_dir} --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --without-http-cache --with-http_ssl_module --with-http_realip_module --with-pcre
make && make install
if [ $? -ne 0 ]
then
    exit 1
fi
/usr/local/nginx/sbin/nginx

需要提前下好nginx源码包放置nginx.yml同一目录

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://sulao.cn/post/723.html

我要评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。