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/fileswith themkdir -p roles/nginx_install/filescommand, then add yournginx.conffile to this folder. - Then, make a new task to copy the
nginx.conffile. Edit the existingroles/nginx_install/tasks/main.ymlfile 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.conffile from yourfilesdirectory to the/etc/nginx/directory on your remote server. - Next, we’ll define a handler within Ansible. Handlers are...