Hello every one. I just started learning Ansible. I am trying to use ansible to install and configure nginx. My ansible
play-book installs and configures nginx alright but each time I try to launch the website I get a 404 file not found error.
The website consists of a single web page saying “Welcome to Ansible” and displaying the Ansible logo.
My playbook contents is as follows:
---
- hosts: remote
gather_facts: False
become: true
tasks:
- name: Install NGINX
apt: pkg=nginx state=present update_cache=true
notify:
- start nginx
become_user: root
- name: copy the nginx config file and restart nginx
copy:
src: /home/abdul/ansible-tutorial/static_site.cfg
dest: /etc/nginx/sites-available/static_site.cfg
become_user: root
- name: create symlink
file:
src: /etc/nginx/sites-available/static_site.cfg
dest: /etc/nginx/sites-enabled/default
state: link
become_user: root
- name: copy contents of site
copy:
src: /home/abdul/ansible-tutorial/static_site_src/
dest: /home/abdul/static_site
- name: restart nginx
The contents of my nginx config file is as follows:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /home/abdul/static_site;
index index.html index.htm;
server_name abdulnginxtest.com;
location / {
try_files $uri $uri/ =404;
}
}
The content of my ansible host file is as follows:
# hosts
[remote]
host1 ansible_host=xxx.xxx.xxx.xxx ansible_user=abdul
/home/abdul/static_site is where I have the website. In it is a page index.html with the following html code:
<h1>Welcome to Ansible</h1>
<img src="/ansible_logo.png" />
(I have also tried ./ansible_logo.png)
The folder also contains the ansible logo referenced in the index.html page
I am running Windows 10 and on it I am running Windows Subsystem for Linux (WSL), which is where I have installed Ansible.
I should point out that the domain abdulnginxtest.com
is not registered with any DNS provider. I am using the OS hosts to test.
The problem is that I don’t whether I should use the Windows hosts file or the WSL hosts file. Currently I have the following entry
in both of them:
xxx.xxx.xxx.xxx abdulnginxtest.com
I have tested both in Mozilla running off the Windows OS and the lynx browser running off the WSL. I still have the 404 Not found error.
Please I would be glad for any pointers showing what I am doing wrong. Thanks