Nginx无法通过Ansible重新启动

Nginx无法通过Ansible重新启动,nginx,ansible,Nginx,Ansible,我在一个剧本中有一个任务,它试图像往常一样通过处理程序重新启动nginx: - name: run migrations command: bash -lc "some command" notify: restart nginx 但是,剧本因此错误而中断: NOTIFIED: [deploy | restart nginx] ******************************************** failed: [REDACTED] => {"failed"

我在一个剧本中有一个任务,它试图像往常一样通过处理程序重新启动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上。

处理程序是:

- name: restart nginx
  service: name=nginx state=restarted enabled=yes
似乎状态和启用标志不能同时存在。通过将上述内容调整为以下内容,它起到了作用

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

我不知道为什么会出现这种情况,以及它为什么突然中断。

似乎您的处理程序需要
sudo
sudo
不是该模块支持的参数。如果您需要在处理程序中显示
sudo:yes
,则需要一行代码。在
服务
模块行上不
sudo=yes
。如果仍然不起作用,请发布更新的处理程序和完整的错误消息。