Ansible not restarting service correctly

ansibleansible-playbook

I am trying to restart the vsftpd service using a handler, based on changes to the config file. I have the following code in tasks/main.yaml:

- name: copy vsftpd.conf
  template: src=vsftpd.conf.j2 dest={{vsftpd_config_file}} backup=yes
  become: yes
  notify: restart vsftpd
  tags: [ 'configuration', 'package', 'vsftpd' ]

and this in handlers/main.yaml:

---
- name: restart vsftpd
  service: name={{ vsftpd_service_name }} state=restarted

the variables are defined as such, in defaults/main.yaml:

vsftpd_config_file: '/etc/vsftpd/vsftpd.conf'
vsftpd_service_name: 'vsftpd'

The handler gets called when I run the playbook:

...
TASK [linux-vsftpd : copy vsftpd.conf] **********************************************************************************************************************
changed: [ftp_host]
...
RUNNING HANDLER [linux-vsftpd : restart vsftpd] *************************************************************************************************************
changed: [ftp_host]

but the service doesn't get restarted:

[elliott.barrere@ftp_host ~]$ ps aux | grep vsftpd
248003150 10437 0.0  0.0 103304   896 pts/0    S+   14:23   0:00 grep vsftpd
root     51182  0.0  0.0  52120   852 ?        Ss   12:25   0:01 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

I can restart the service manually using the service script and the timestamp updates like I would expect:

[elliott.barrere@ftp_host ~]$ sudo service vsftpd restart
[sudo] password for elliott.barrere: 
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
[elliott.barrere@ftp_host ~]$ ps aux | grep vsftpd
root     38995  0.0  0.0  52120   852 ?        Ss   14:23   0:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
248003150 46878 0.0  0.0 103300   884 pts/0    S+   14:23   0:00 grep vsftpd
[elliott.barrere@ftp_host ~]$ 

Any ideas why Ansible isn't restarting the service, or worse, why it isn't reporting a failure?

Best Answer

Ah, well as soon as I posted the question I realized my issue: I'm missing the "become: yes" in my handler:

---
- name: restart vsftpd
  become: yes
  service: name={{ vsftpd_service_name }} state=restarted

Adding that line fixes the issue and Ansible is able to restart the service.

For some reason it looks like the vsftpd init script does not exit properly when run as a non-root user:

[elliott.barrere@ftp_host ~]$ service vsftpd restart
Shutting down vsftpd:                                      [FAILED]
Starting vsftpd for vsftpd: 500 OOPS: config file not owned by correct user, or not a file
                                                           [FAILED]
[elliott.barrere@ftp_host ~]$ echo $?
0

So that was making it hard to track down.