ansible-playbook 编译安装nginx

mkdir /etc/ansible/roles/nginx/{files,templates,tasks,handlers,vars,default,meta} -pv

└── nginx

    ├── default

    ├── files

    │ └── nginx-1.12.2.tar.gz

    ├── handlers

    │ └── main.yml

    ├── meta

    ├── tasks

    │ └── main.yml

    ├── templates

    │ ├── index.html.j2

    │ └── nginx.conf.j2

    └── vars

 

cat nginx/tasks/main.yml

- name: copy nginx

  copy: src=nginx-1.12.2.tar.gz dest=/usr/local/src/

- name: yum pcre pcre-devel openssl openssl-devel zlib zlib-devel gcc-c++

  yum: name={{ item }} state=present

  with_items:

  - pcre

  - pcre-devel

  - openssl

  - openssl-devel

  - zlib

  - zlib-devel

  - gcc-c++

- name: tar nginx

  shell: chdir=/usr/local/src tar -zxf nginx-1.12.2.tar.gz

- name: install nginx

  shell: chdir=/usr/local/src/nginx-1.12.2 ./configure && make && make install

- name: copy nginx.conf

  template: src=nginx.conf.j2 dest=/usr/local/nginx/conf/nginx.conf

- name: copy index.html

  template: src=index.html.j2 dest=/usr/local/nginx/html/index.html

- name: open 80

  shell: firewall-cmd --zone=public --add-port=80/tcp --permanent

  notify:

  - restart firewall

- name: open nginx

  shell: /usr/local/nginx/sbin/nginx

 

cat nginx/handlers/main.yml

- name: restart firewall

  service: name=firewalld state=restarted

 

cat nginx/templates/index.html.j2

<!DOCTYPE html>

<html>

<head>

<title>{{ ansible_all_ipv4_addresses }}</title>

</style>

</head>

<body>

<h1>This is {{ ansible_fqdn }} index page IP is {{ ansible_all_ipv4_addresses }}</h1>

</body>

</html>

 

 cat nginx/templates/nginx.conf.j2

#user  nobody;

worker_processes  {{ ansible_processor_vcpus }}; //其余的没有变

 

cat nginx.yml

- hosts: nginx

 remote_user: root

 roles:

   - nginx

转载于:https://www.cnblogs.com/xuyingzhong/p/8450249.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值