Nginx cannot restart via Ansible

99封情书 提交于 2020-01-01 10:54:12

问题


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.

The handler is standard:

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

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

This is on a ubuntu-14-04-x64 VPS.


回答1:


The handler was:

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



来源:https://stackoverflow.com/questions/27057992/nginx-cannot-restart-via-ansible

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!