Ansible deployment git clone: "local variable 'remote_head' referenced before assignment"

795 views Asked by At

I've got a git clone task defined in my Ansible playbook:

- name: Clone website git repository
  git: >
    dest=/var/www/mywebsite
    [email protected]:MyOrganisation/MyWebsite.git
    update=yes
    force=yes
    accept_hostkey=yes
    version="{{ git_branch }}"
  become: yes
  become_user: www-data
  register: cloned

This works perfectly fine the first time I deploy this to a machine, but when I run it a second time (to update the code to the latest version) I get the following error:

TASK [Clone git repository]


fatal: [188.xxx.xx.xxx]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to 188.xxx.xx.xxx closed.\r\n", "module_stdout": "\r\nTraceback (most recent call last):\r\n File "/tmp/ansible_7diacW/ansible_module_git.py", line 1040, in \r\n main()\r\n File "/tmp/ansible_7diacW/ansible_module_git.py", line 994, in main\r\n result.update(changed=True, after=remote_head, msg='Local modifications exist')\r\nUnboundLocalError: local variable 'remote_head' referenced before assignment\r\n", "msg": "MODULE FAILURE"} to retry, use: --limit @/Users/kramer65/repos/mywebsite/ansible/php.retry

I'm unsure what the problem is here. What is the local variable 'remote_head'? And why is it referenced before assignment?

Does anybody know what's going on here?

1

There are 1 answers

0
kramer65 On BEST ANSWER

Following the issue link given in the comment by @techraf I found a Pull Request got merged in which they say it's "Merged to devel and backported to stable-2.2.".

I just upgraded my ansible version from 2.2.0.0 to 2.2.0.0_2 and it now works for me again.

Thanks @techraf

[EDIT]

I small rectification. It seems to work *better now. With that I mean that it often works, but sometimes not. If it doesn't work, running it again often seems to do the job for me. If anyone else has better ideas, I'm happy to hear them.