Nginx cannot restart through Ansible

I have a task in a playbook that tries to reload nginx through a handler, as usual:

- name: run migrations
  command: bash -lc "some command"
  notify: restart nginx

Playback however violates this error:

NOTIFIED: [deploy | restart nginx] ******************************************** 
failed: [REDACTED] => {"failed": true}
msg: failure 1 running systemctl show for 'nginx.service': Failed to get D-Bus connection: No connection to service manager.

The handler is standard:

- name: restart nginx
  service: name=nginx state=restarted enabled=yes

And the way I configured nginx is also extraordinary:

- name: install nginx
  apt: name=nginx state=present
  sudo: yes

- name: copy nginx.conf to the server
  template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
  sudo: yes

- name: delete default virtualhost
  file: path=/etc/nginx/sites-enabled/default state=absent
  sudo: yes

- name: add mysite site-available
  template: src=mysite.conf.j2 dest=/etc/nginx/sites-available/mysite.conf
  sudo: yes

- name: link mysite site-enabled
  file: path=/etc/nginx/sites-enabled/mysite src=/etc/nginx/sites-available/mysite.conf state=link
  sudo: yes

This is on the ubuntu-14-04-x64VPS.

+4
source share
1 answer

The handler was:

- name: restart nginx
  service: name=nginx state=restarted enabled=yes

It seems that the status and enabled flags may not be present. By trimming the above, it worked.

- name: restart nginx
  service: name=nginx state=restarted

Why this is so, and why it suddenly began to break, I do not know.

+9
source

All Articles