Nginx cannot restart via Ansible
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.
Simpleton
To paraphrase Socrates, the only thing that I know is that I know nothing about programming. Thus, I'm always re-learning: Ruby, Rails, Sinatra JavaScript, JQuery, Angular.js, Backbone.js Redis, MongoDB, PostgreSQL, MySQL GoLang CSS/HTML, because you can never master the basics well enough. The tools I use: Git, Unix, Heroku, AWS, Sublime Text 2, RSpec Follow me on Twitter: @cynicalgrinch
Updated on June 30, 2022Comments
-
Simpleton almost 2 years
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.