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