Nginx 无法通过 Ansible 重新启动

标签 nginx ansible

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

我不知道这是为什么,以及为什么它突然开始破裂。

关于Nginx 无法通过 Ansible 重新启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27057992/

上一篇:SQL插入多行

下一篇:Eclipse 隐形编辑器

相关文章:

powershell - Invoke-Command AsJob 参数集不起作用

ansible - 如何修复 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' 没有属性 'value' 错误

ansible - 如何在 vars 中使用注册的 ansible 变量的字典?

ssh - 是否有任何条件或事实可以检查主机是否可以使用SSH成功​​登录另一台服务器?

nginx - nginx 守护进程开/关选项有什么区别?

nginx - 如何使用 ffmpeg 将 boxblur 添加到 rtmp 流

git - 使用gitlab自动部署

nginx - 登录错误URL后的phpmyadmin

nginx - [::] 在我的 nginx 配置文件中是什么意思

Ansible - 重试任务,直到文件包含日志行