在CentOS 7上使用Ansible安装Nginx
# nginx_install.yml
---
- name: Install Nginx on CentOS 7
hosts: webservers
become: yes
tasks:
- name: Install EPEL repository if not present
package:
name: epel-release
state: present
- name: Install necessary dependencies
package:
name:
- gcc
- gcc-c++
- make
- pcre-devel
- zlib-devel
- openssl-devel
state: present
- name: Add the Nginx repository
yum_repository:
name: nginx
description: Nginx Repository
baseurl: https://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck: no # 或者提供GPG key来验证包签名
- name: Install Nginx
package:
name: nginx
state: latest
- name: Start and enable Nginx service
service:
name: nginx
state: started
enabled: yes