Setting up NGINX using Ansible
In the last section, we made a project called nginx_install
. We’ll continue with this project in order to have Ansible write the nginx.conf
file for us. So let’s get started:
- First, create a directory at
roles/nginx_install/files
with themkdir -p roles/nginx_install/files
command, then add yournginx.conf
file to this folder. - Then, make a new task to copy the
nginx.conf
file. Edit the existingroles/nginx_install/tasks/main.yml
file and add the following:- name: Copy nginx configuration file copy: src: nginx.conf dest: /etc/nginx/nginx.conf owner: root group: root mode: '0644' notify: restart nginx
This will send the
nginx.conf
file from yourfiles
directory to the/etc/nginx/
directory on your remote server. - Next, we’ll define a handler within Ansible. Handlers are...