Ubuntu – Ansible fails to restart service – why

ansibleUbuntu

I'm trying this on AWS EC2 instance running Ubuntu 14.04.
I have a task that notifies a handler. When the handler is run I get an error. I'm having trouble understanding the error message and therefore I cannot debug it.

The task:

- name: Set post_max_size to 100M
  sudo: yes
  lineinfile: dest=/etc/php5/fpm/php.ini regexp='^;?post_max_size =' line='post_max_size = 100M'
  notify:
    - restart php5-fpm

The handlers

---
- name: start php5-fpm
  service: name=php5-fpm state=started

- name: restart php5-fpm
  service: name=php5-fpm state=restarted

The error I get

NOTIFIED: [php | restart php5-fpm] ********************************************
<54.154.82.195> ESTABLISH CONNECTION FOR USER: ubuntu
<54.154.82.195> REMOTE_MODULE service name=php5-fpm state=restarted
<54.154.82.195> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 54.154.82.195 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1433866104.51-11364253366998 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1433866104.51-11364253366998 && echo $HOME/.ansible/tmp/ansible-tmp-1433866104.51-11364253366998'
<52.16.161.67> ESTABLISH CONNECTION FOR USER: ubuntu
<52.16.161.67> REMOTE_MODULE service name=php5-fpm state=restarted
<52.16.161.67> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 52.16.161.67 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1433866104.51-159732570027917 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1433866104.51-159732570027917 && echo $HOME/.ansible/tmp/ansible-tmp-1433866104.51-159732570027917'
<52.16.161.67> PUT /tmp/tmpyZ8NZb TO /home/ubuntu/.ansible/tmp/ansible-tmp-1433866104.51-159732570027917/service
<54.154.82.195> PUT /tmp/tmp67pMQt TO /home/ubuntu/.ansible/tmp/ansible-tmp-1433866104.51-11364253366998/service
<52.16.161.67> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 52.16.161.67 /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=pkjcazbngchlcujcryxpjhqvysuogqdq] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-pkjcazbngchlcujcryxpjhqvysuogqdq; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1433866104.51-159732570027917/service; rm -rf /home/ubuntu/.ansible/tmp/ansible-tmp-1433866104.51-159732570027917/ >/dev/null 2>&1'"'"''
<54.154.82.195> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/vagrant/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 54.154.82.195 /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=kmaknhfrafsrngyemkpxdkifpezqbtui] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-kmaknhfrafsrngyemkpxdkifpezqbtui; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1433866104.51-11364253366998/service; rm -rf /home/ubuntu/.ansible/tmp/ansible-tmp-1433866104.51-11364253366998/ >/dev/null 2>&1'"'"''
failed: [54.154.82.195] => {"failed": true}
failed: [52.16.161.67] => {"failed": true}

Best Answer

It seems that it is a bug related to Ansible version 1.9.1

https://github.com/ansible/ansible-modules-core/issues/1170

Patching with the suggested patch and everything worked.