Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx cannot restart via Ansible

Tags:

nginx

ansible

I have a task in a playbook that tries to restart nginx via a handler as per usual:

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

The playbook however breaks on 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 that I've setup nginx is not out of the ordinary as well:

- 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 a ubuntu-14-04-x64 VPS.

like image 402
Simpleton Avatar asked Nov 21 '14 09:11

Simpleton


1 Answers

The handler was:

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

It seems that the state and enabled flags cannot both be present. By trimming the above to the following, it worked.

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

Why this is, and why it started breaking suddenly, I do not know.

like image 128
Simpleton Avatar answered Sep 30 '22 09:09

Simpleton