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

查看:60
本文介绍了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 上.

This is on a 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天全站免登陆