Nginx无法通过Ansible重新启动 [英] Nginx cannot restart via Ansible

查看:182
本文介绍了Nginx无法通过Ansible重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在剧本中有一个任务,试图照常通过处理程序重启nginx:

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.

该处理程序是标准的:

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

我设置nginx的方式也不例外:

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

这是在ubuntu-14-04-x64 VPS上.

推荐答案

处理程序为:

- 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.

这篇关于Nginx无法通过Ansible重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆