Ansible没有正确重启服务

我正在尝试使用处理程序重新启动vsftpd服务,基于configuration文件的更改。 在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' ] 

和这个在处理程序/ main.yaml:

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

这些variables是这样定义的,在defaults / main.yaml中:

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

当我运行剧本时,处理程序被调用:

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

但该服务不会重新启动:

 [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 

我可以使用服务脚本和时间戳更新手动重新启动服务,就像我所期望的那样:

 [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 ~]$ 

任何想法为什么Ansible不重新启动服务,或者更糟糕,为什么它不报告失败?

嗯,当我发布这个问题时,我意识到了我的问题:我错过了我的处理程序中的“成为:是”

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

添加该行解决了问题,Ansible能够重新启动服务。

出于某种原因,它看起来像以非root用户身份运行时,vsftpd init脚本不能正确退出:

 [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 

所以这是很难追查。