title: Using ansible to launch nginx web server: localhost:8080 not responding
body: <p>I am experimenting with Ansible by reading the great <em>Ansible Up and Running</em> book by  Lorin Hochstein.</p>
  
  <p>On a Ubuntu 16.04 machine with Ansible, I am trying now to run the <em>web-tls</em> playbook.</p>
  
  <p>As example, I created a <em>web-notls.yml</em> file and I did put in the <em>playbook</em> directory:</p>
  
  <pre><code>    - name: Configure webserver with nginx
  hosts: webservers
  sudo: True
  tasks:
  - name: install nginx
  apt: name=nginx update_cache=yes
  - name: copy nginx config file
  copy: src=files/nginx.conf dest=/etc/nginx/sites-available/default
  - name: enable configuration
  file: &gt;
  dest=/etc/nginx/sites-enabled/default
  src=/etc/nginx/sites-available/default
  state=link
  - name: copy index.html
  template: src=templates/index.html.j2 dest=/usr/share/nginx/html/index.html
  mode=0644
  - name: restart nginx
  service: name=nginx state=restarted
  </code></pre>
  
  <p>I also specified a <em>nginx.conf</em>file and I did put it in <em>playbooks/files/nginx.conf</em> directory:</p>
  
  <pre><code>   server {
  listen 80 default_server;
  listen [::]:80 default_server ipv6only=on;
  root /usr/share/nginx/html;
  index index.html index.htm;
  server_name localhost;
  location / {
  try_files $uri $uri/ =404;
  }
  }
  </code></pre>
  
  <p>I also created hosts file to access the Vagrant machine easily and a web custom homepage to see a message after accessing the web page.</p>
  
  <p>I modified the <em>Vagrantfile</em> to contain this code:</p>
  
  <pre><code>VAGRANTFILE_API_VERSION = "2"
  Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "forwarded_port", guest: 443, host: 8443
  end
  </code></pre>
  
  <p>After this change, the port 8080 on my local machine should be forwarded t othe port 80 of the Vagrant machine, and the port 8443 on my local machine should be forwarded to ort 443 on the vagrant machine:
  <a href="https://i.stack.imgur.com/3qbrY.png" rel="nofollow noreferrer">8080 Port forwarding Architecture</a>
  When trying to run the playbook by:</p>
  
  <pre><code>$ ansible-playbook web-notls.yml
  </code></pre>
  
  <p>the ouput is:</p>
  
  <pre><code>luigi@luigi-H87-HD3:~/playbooks$ ansible-playbook web-notls.yml 
  [DEPRECATION WARNING]: [defaults]hostfile option, The key is misleading as it can also be a list of 
  hosts, a directory or a list of paths , use [defaults] inventory=/path/to/file|dir instead. This 
  feature will be removed in version 2.8. Deprecation warnings can be disabled by setting 
  deprecation_warnings=False in ansible.cfg.
  [DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and make sure become_method
   is 'sudo' (default). This feature will be removed in version 2.6. Deprecation warnings can be 
  disabled by setting deprecation_warnings=False in ansible.cfg.
  
  PLAY [Configure webserver with nginx] ***************************************************************
  
  TASK [Gathering Facts] ******************************************************************************
  ok: [testserver]
  
  TASK [install nginx] ********************************************************************************
  ok: [testserver]
  
  TASK [copy nginx config file] ***********************************************************************
  ok: [testserver]
  
  TASK [enable configuration] *************************************************************************
  ok: [testserver]
  
  TASK [copy index.html] ******************************************************************************
  ok: [testserver]
  
  TASK [restart nginx] ********************************************************************************
  changed: [testserver]
  
  PLAY RECAP ******************************************************************************************
  testserver                 : ok=6    changed=1    unreachable=0    failed=0 
  </code></pre>
  
  <p>It seems like no errors so far. I am now trying to open <em>localhost:8080</em> address by browser on my local machine (I also tried to do a vagrant ssh and try curl localhost:8080 with no success) but I receive no results. What am I doing wrong ?</p>
  
  <p>Thank you in advance!</p>