0

I have completed my ansible+vagrant integration which is here. Playbook installs everything i've instructed. does every file modification as instructed. But when i check on my local machine using http:localhost:8080 or http://127.0.0.1:8080 it never works for index.php file. It always downloads the file. So in order to get it working i've to login to vagrant box and hit below commands to server in order to serve php page.

sudo service nginx restart
sudo service php7.0-fpm restart

I already defined a handler for restarting service which is as below.

- name: "restart services"
  service: >
    name= "{{ item }}"
    state=restarted
  with_items:
    - nginx
    - php7.0-fpm

I have a task that takes application git clone. which is as below.

- name: Application git clone
  git: 
    repo: https://github.com/shaileshsutar88/deploy.git
    dest: /var/www/html
  notify:
    - restart services

I am not sure what I am doing wrong here or if I am missing anything. Otherwise I would like know more about ansible execution flow. When i check ansible execution with verbose, it says ok which means handlers are not running. I am wondering why it's not running handlers since I am calling it after git clone of my application.

RUNNING HANDLER [web : restart services] ***************************************
ok: [web] => (item=nginx) => {"changed": false, "failed": false, "item": "nginx", "name": "", "status": {}}
ok: [web] => (item=php7.0-fpm) => {"changed": false, "failed": false, "item": "php7.0-fpm", "name": "", "status": {}}
Shailesh Sutar
  • 1,427
  • 4
  • 22
  • 40

1 Answers1

1

If your NGINX is starting to download a file this normally means that your PHP Handler is configured wrong. Did you try to create a robots.txt for example and try to open this? Should work without the need to download it.

As Konstantin mentioned yesterday you should use handlers. I read your github repo and saw that you defined an "reload services" handler, but never used it ( or at least I did not see it )

You need to do this with:

  - name: write the apache config file
    template:
      src: /srv/httpd.j2
      dest: /etc/httpd.conf
    notify:
      - reload services
  • I was able to solve the issue by calling handler in edit-config task so issue is resolved. I was calling handlers after a task which was not making any change in configuration of these services. Now I am calling it in correct task where it needs to called. – Shailesh Sutar Dec 06 '17 at 08:09