Skip to content

Instantly share code, notes, and snippets.

@ragingprodigy
Created December 18, 2017 04:57
Show Gist options
  • Save ragingprodigy/629f59555bd26aa281a0d669ad25b487 to your computer and use it in GitHub Desktop.
Save ragingprodigy/629f59555bd26aa281a0d669ad25b487 to your computer and use it in GitHub Desktop.
Ansible Playbook to Install Nginx
---
- hosts: all
sudo: yes
tasks:
- name: check registered the repository of nginx-release
shell: rpm -qa | grep nginx-release
register: result
ignore_errors: True
always_run: yes
changed_when: no
- name: add repository nginx-release (CentOS6/CentOS7)
yum: name="http://nginx.org/packages/centos/{{ansible_distribution_major_version}}/noarch/RPMS/nginx-release-centos-{{ansible_distribution_major_version}}-0.el{{ansible_distribution_major_version}}.ngx.noarch.rpm"
when: result|failed
- name: disable the repository (pls set --enablerepo=nginx if you use it)
replace: dest=/etc/yum.repos.d/nginx.repo regexp="enabled *= *1" replace="enabled=0"
ignore_errors: True
- name: install nginx
yum: name=nginx state=present enablerepo=nginx
- name: Start Nginx
service: name=nginx enabled=yes state=started
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment