Nginx无法通过Ansible重新启动

时间:2014-11-21 09:25:32

标签: nginx ansible

我在Playbook中有一个任务,试图通过处理程序按照惯例重新启动nginx:

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

然而,剧本打破了这个错误:

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.

处理程序是标准的:

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

我设置nginx的方式也不同寻常:

- 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

这是ubuntu-14-04-x64 VPS。

1 个答案:

答案 0 :(得分:11)

处理程序是:

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

似乎状态和启用的标志不能同时存在。通过修改以上内容,它起作用了。

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

为什么会这样,为什么它突然突然爆发,我不知道。